Skip to content

Commit 0887bba

Browse files
Properly handle opening of file-less excerpts
1 parent a0f2c07 commit 0887bba

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

crates/editor/src/editor.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12833,6 +12833,27 @@ impl Editor {
1283312833
};
1283412834

1283512835
for (buffer, (ranges, scroll_offset)) in new_selections_by_buffer {
12836+
// Handle file-less buffers separately: those are not really the project items, so won't have a paroject path or entity id,
12837+
// so `workspace.open_project_item` will never find them, always opening a new editor.
12838+
// Instead, we try to activate the existing editor in the pane first.
12839+
if buffer.read(cx).file().is_none() {
12840+
let pane_item_index =
12841+
pane.read(cx).items().enumerate().find_map(|(i, item)| {
12842+
let editor = item.downcast::<Editor>()?;
12843+
let singleton_buffer =
12844+
editor.read(cx).buffer().read(cx).as_singleton()?;
12845+
if singleton_buffer == buffer {
12846+
Some(i)
12847+
} else {
12848+
None
12849+
}
12850+
});
12851+
if let Some(index) = pane_item_index {
12852+
pane.update(cx, |pane, cx| pane.activate_item(index, true, true, cx));
12853+
continue;
12854+
}
12855+
}
12856+
1283612857
let editor =
1283712858
workspace.open_project_item::<Self>(pane.clone(), buffer, true, true, cx);
1283812859
editor.update(cx, |editor, cx| {

0 commit comments

Comments
 (0)