Fix panic in drag entered (#10277)
Co-Authored-By: Kirill <kirill@zed.dev> Release Notes: - Fixed panic when dragging into Zed. Optionally, include screenshots / media showcasing your addition that can be included in the release notes. **or** - N/A Co-authored-by: Kirill <kirill@zed.dev>
This commit is contained in:
@@ -1848,16 +1848,17 @@ extern "C" fn accepts_first_mouse(this: &Object, _: Sel, _: id) -> BOOL {
|
|||||||
|
|
||||||
extern "C" fn dragging_entered(this: &Object, _: Sel, dragging_info: id) -> NSDragOperation {
|
extern "C" fn dragging_entered(this: &Object, _: Sel, dragging_info: id) -> NSDragOperation {
|
||||||
let window_state = unsafe { get_window_state(this) };
|
let window_state = unsafe { get_window_state(this) };
|
||||||
if send_new_event(&window_state, {
|
let position = drag_event_position(&window_state, dragging_info);
|
||||||
let position = drag_event_position(&window_state, dragging_info);
|
let paths = external_paths_from_event(dragging_info);
|
||||||
let paths = external_paths_from_event(dragging_info);
|
if let Some(event) =
|
||||||
PlatformInput::FileDrop(FileDropEvent::Entered { position, paths })
|
paths.map(|paths| PlatformInput::FileDrop(FileDropEvent::Entered { position, paths }))
|
||||||
}) {
|
{
|
||||||
window_state.lock().external_files_dragged = true;
|
if send_new_event(&window_state, event) {
|
||||||
NSDragOperationCopy
|
window_state.lock().external_files_dragged = true;
|
||||||
} else {
|
return NSDragOperationCopy;
|
||||||
NSDragOperationNone
|
}
|
||||||
}
|
}
|
||||||
|
NSDragOperationNone
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" fn dragging_updated(this: &Object, _: Sel, dragging_info: id) -> NSDragOperation {
|
extern "C" fn dragging_updated(this: &Object, _: Sel, dragging_info: id) -> NSDragOperation {
|
||||||
@@ -1895,10 +1896,13 @@ extern "C" fn perform_drag_operation(this: &Object, _: Sel, dragging_info: id) -
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn external_paths_from_event(dragging_info: *mut Object) -> ExternalPaths {
|
fn external_paths_from_event(dragging_info: *mut Object) -> Option<ExternalPaths> {
|
||||||
let mut paths = SmallVec::new();
|
let mut paths = SmallVec::new();
|
||||||
let pasteboard: id = unsafe { msg_send![dragging_info, draggingPasteboard] };
|
let pasteboard: id = unsafe { msg_send![dragging_info, draggingPasteboard] };
|
||||||
let filenames = unsafe { NSPasteboard::propertyListForType(pasteboard, NSFilenamesPboardType) };
|
let filenames = unsafe { NSPasteboard::propertyListForType(pasteboard, NSFilenamesPboardType) };
|
||||||
|
if filenames == nil {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
for file in unsafe { filenames.iter() } {
|
for file in unsafe { filenames.iter() } {
|
||||||
let path = unsafe {
|
let path = unsafe {
|
||||||
let f = NSString::UTF8String(file);
|
let f = NSString::UTF8String(file);
|
||||||
@@ -1906,7 +1910,7 @@ fn external_paths_from_event(dragging_info: *mut Object) -> ExternalPaths {
|
|||||||
};
|
};
|
||||||
paths.push(PathBuf::from(path))
|
paths.push(PathBuf::from(path))
|
||||||
}
|
}
|
||||||
ExternalPaths(paths)
|
Some(ExternalPaths(paths))
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" fn conclude_drag_operation(this: &Object, _: Sel, _: id) {
|
extern "C" fn conclude_drag_operation(this: &Object, _: Sel, _: id) {
|
||||||
|
|||||||
Reference in New Issue
Block a user