preview tabs: Allow replacing preview tab when using code navigation (#10730)
This PR adds support for replacing the current preview tab when using GoToDefinition. Previously a tab, that was navigated away from, was converted into a permanent tab and the new tab was opened as preview. Without `enable_preview_from_code_navigation`: https://github.com/zed-industries/zed/assets/53836821/99840724-d6ff-4738-a9c4-ee71a0001634 With `enable_preview_from_code_navigation`: https://github.com/zed-industries/zed/assets/53836821/8c60efcb-d597-40bf-b08b-13faf5a289b6 Note: In the future I would like to improve support for the navigation history, because right now tabs that are not "normal" project items, e.g. FindAllReferences cannot be reopened Release Notes: - Added support for replacing the current preview tab when using code navigation (`enable_preview_from_code_navigation`)
This commit is contained in:
parent
9ff847753e
commit
20625e98ad
19 changed files with 120 additions and 60 deletions
|
@ -130,7 +130,7 @@ use ui::{
|
|||
Tooltip,
|
||||
};
|
||||
use util::{defer, maybe, post_inc, RangeExt, ResultExt, TryFutureExt};
|
||||
use workspace::item::ItemHandle;
|
||||
use workspace::item::{ItemHandle, PreviewTabsSettings};
|
||||
use workspace::notifications::NotificationId;
|
||||
use workspace::{
|
||||
searchable::SearchEvent, ItemNavHistory, SplitDirection, ViewId, Workspace, WorkspaceId,
|
||||
|
@ -1610,6 +1610,7 @@ impl Editor {
|
|||
{
|
||||
workspace.add_item_to_active_pane(
|
||||
Box::new(cx.new_view(|cx| Editor::for_buffer(buffer, Some(project.clone()), cx))),
|
||||
None,
|
||||
cx,
|
||||
);
|
||||
}
|
||||
|
@ -3781,7 +3782,7 @@ impl Editor {
|
|||
let project = workspace.project().clone();
|
||||
let editor =
|
||||
cx.new_view(|cx| Editor::for_multibuffer(excerpt_buffer, Some(project), cx));
|
||||
workspace.add_item_to_active_pane(Box::new(editor.clone()), cx);
|
||||
workspace.add_item_to_active_pane(Box::new(editor.clone()), None, cx);
|
||||
editor.update(cx, |editor, cx| {
|
||||
editor.highlight_background::<Self>(
|
||||
&ranges_to_highlight,
|
||||
|
@ -8102,14 +8103,23 @@ impl Editor {
|
|||
cx,
|
||||
);
|
||||
});
|
||||
|
||||
let item = Box::new(editor);
|
||||
let item_id = item.item_id();
|
||||
|
||||
if split {
|
||||
workspace.split_item(SplitDirection::Right, item.clone(), cx);
|
||||
} else {
|
||||
workspace.add_item_to_active_pane(item.clone(), cx);
|
||||
let destination_index = workspace.active_pane().update(cx, |pane, cx| {
|
||||
if PreviewTabsSettings::get_global(cx).enable_preview_from_code_navigation {
|
||||
pane.close_current_preview_item(cx)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
});
|
||||
workspace.add_item_to_active_pane(item.clone(), destination_index, cx);
|
||||
}
|
||||
workspace.active_pane().clone().update(cx, |pane, cx| {
|
||||
let item_id = item.item_id();
|
||||
workspace.active_pane().update(cx, |pane, cx| {
|
||||
pane.set_preview_item_id(Some(item_id), cx);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue