From 4525f7bd6b7a038863b300d69f50e54ad35db617 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Tue, 3 Dec 2024 18:19:09 +0200 Subject: [PATCH] Style fixes --- crates/editor/src/editor.rs | 48 ++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index ae8d8576d6d69a..1e47eb46a891b0 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -12833,25 +12833,32 @@ impl Editor { }; for (buffer, (ranges, scroll_offset)) in new_selections_by_buffer { - // Handle file-less buffers separately: those are not really the project items, so won't have a paroject path or entity id, - // so `workspace.open_project_item` will never find them, always opening a new editor. - // Instead, we try to activate the existing editor in the pane first. - let editor = if buffer.read(cx).file().is_none() { - let pane_item_index = - pane.read(cx).items().enumerate().find_map(|(i, item)| { - let editor = item.downcast::()?; - let singleton_buffer = - editor.read(cx).buffer().read(cx).as_singleton()?; - if singleton_buffer == buffer { - Some((editor, i)) - } else { - None - } + let editor = buffer + .read(cx) + .file() + .is_none() + .then(|| { + // Handle file-less buffers separately: those are not really the project items, so won't have a paroject path or entity id, + // so `workspace.open_project_item` will never find them, always opening a new editor. + // Instead, we try to activate the existing editor in the pane first. + let (editor, pane_item_index) = + pane.read(cx).items().enumerate().find_map(|(i, item)| { + let editor = item.downcast::()?; + let singleton_buffer = + editor.read(cx).buffer().read(cx).as_singleton()?; + if singleton_buffer == buffer { + Some((editor, i)) + } else { + None + } + })?; + pane.update(cx, |pane, cx| { + pane.activate_item(pane_item_index, true, true, cx) }); - if let Some((editor, index)) = pane_item_index { - pane.update(cx, |pane, cx| pane.activate_item(index, true, true, cx)); - editor - } else { + Some(editor) + }) + .flatten() + .unwrap_or_else(|| { workspace.open_project_item::( pane.clone(), buffer, @@ -12859,10 +12866,7 @@ impl Editor { true, cx, ) - } - } else { - workspace.open_project_item::(pane.clone(), buffer, true, true, cx) - }; + }); editor.update(cx, |editor, cx| { let autoscroll = match scroll_offset {