mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-20 02:47:34 +03:00
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:
parent
4d68bf2fa6
commit
9b88259b1f
@ -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 {
|
||||
let window_state = unsafe { get_window_state(this) };
|
||||
if send_new_event(&window_state, {
|
||||
let position = drag_event_position(&window_state, dragging_info);
|
||||
let paths = external_paths_from_event(dragging_info);
|
||||
PlatformInput::FileDrop(FileDropEvent::Entered { position, paths })
|
||||
}) {
|
||||
window_state.lock().external_files_dragged = true;
|
||||
NSDragOperationCopy
|
||||
} else {
|
||||
NSDragOperationNone
|
||||
let position = drag_event_position(&window_state, dragging_info);
|
||||
let paths = external_paths_from_event(dragging_info);
|
||||
if let Some(event) =
|
||||
paths.map(|paths| PlatformInput::FileDrop(FileDropEvent::Entered { position, paths }))
|
||||
{
|
||||
if send_new_event(&window_state, event) {
|
||||
window_state.lock().external_files_dragged = true;
|
||||
return NSDragOperationCopy;
|
||||
}
|
||||
}
|
||||
NSDragOperationNone
|
||||
}
|
||||
|
||||
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 pasteboard: id = unsafe { msg_send![dragging_info, draggingPasteboard] };
|
||||
let filenames = unsafe { NSPasteboard::propertyListForType(pasteboard, NSFilenamesPboardType) };
|
||||
if filenames == nil {
|
||||
return None;
|
||||
}
|
||||
for file in unsafe { filenames.iter() } {
|
||||
let path = unsafe {
|
||||
let f = NSString::UTF8String(file);
|
||||
@ -1906,7 +1910,7 @@ fn external_paths_from_event(dragging_info: *mut Object) -> ExternalPaths {
|
||||
};
|
||||
paths.push(PathBuf::from(path))
|
||||
}
|
||||
ExternalPaths(paths)
|
||||
Some(ExternalPaths(paths))
|
||||
}
|
||||
|
||||
extern "C" fn conclude_drag_operation(this: &Object, _: Sel, _: id) {
|
||||
|
Loading…
Reference in New Issue
Block a user