Skip to content

Commit

Permalink
Style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SomeoneToIgnore committed Dec 3, 2024
1 parent 678967e commit 4525f7b
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12833,36 +12833,40 @@ 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::<Editor>()?;
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::<Editor>()?;
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::<Self>(
pane.clone(),
buffer,
true,
true,
cx,
)
}
} else {
workspace.open_project_item::<Self>(pane.clone(), buffer, true, true, cx)
};
});

editor.update(cx, |editor, cx| {
let autoscroll = match scroll_offset {
Expand Down

0 comments on commit 4525f7b

Please sign in to comment.