Add more preview tab settings and fix janky behavior (#43921)
Closes #41495 Known issues: - File path links always open as non-preview tabs. Fixing this is not technically too difficult but requires more invasive changes and so should be done in a future PR. Release Notes: - Fixed strange behavior when reopening closed preview tabs - Overhauled preview tabs settings: - Added setting `preview_tabs.enable_preview_from_project_panel` (default `true`) - Kept setting `preview_tabs.enable_preview_from_file_finder` (default `false`) - Added setting `preview_tabs.enable_preview_from_multibuffer` (default `true`) - Added setting `preview_tabs.enable_preview_multibuffer_from_code_navigation` (default `false`) - Added setting `preview_tabs.enable_preview_file_from_code_navigation` (default `true`) - Renamed setting `preview_tabs.enable_preview_from_code_navigation` to `preview_tabs.enable_keep_preview_on_code_navigation` (default `false`) --------- Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com> Co-authored-by: Cole Miller <cole@zed.dev>
This commit is contained in:
co-authored by
Smit Barmase
Cole Miller
parent
290a1550aa
commit
87976e91cf
+52
-37
@@ -17012,7 +17012,9 @@ impl Editor {
|
||||
})
|
||||
.collect();
|
||||
|
||||
let workspace = self.workspace();
|
||||
let Some(workspace) = self.workspace() else {
|
||||
return Task::ready(Ok(Navigated::No));
|
||||
};
|
||||
|
||||
cx.spawn_in(window, async move |editor, cx| {
|
||||
let locations: Vec<Location> = future::join_all(definitions)
|
||||
@@ -17038,10 +17040,6 @@ impl Editor {
|
||||
}
|
||||
|
||||
if num_locations > 1 {
|
||||
let Some(workspace) = workspace else {
|
||||
return Ok(Navigated::No);
|
||||
};
|
||||
|
||||
let tab_kind = match kind {
|
||||
Some(GotoDefinitionKind::Implementation) => "Implementations",
|
||||
Some(GotoDefinitionKind::Symbol) | None => "Definitions",
|
||||
@@ -17073,11 +17071,14 @@ impl Editor {
|
||||
|
||||
let opened = workspace
|
||||
.update_in(cx, |workspace, window, cx| {
|
||||
let allow_preview = PreviewTabsSettings::get_global(cx)
|
||||
.enable_preview_multibuffer_from_code_navigation;
|
||||
Self::open_locations_in_multibuffer(
|
||||
workspace,
|
||||
locations,
|
||||
title,
|
||||
split,
|
||||
allow_preview,
|
||||
MultibufferSelectionMode::First,
|
||||
window,
|
||||
cx,
|
||||
@@ -17094,10 +17095,9 @@ impl Editor {
|
||||
Ok(Navigated::Yes)
|
||||
}
|
||||
Some(Either::Right(path)) => {
|
||||
let Some(workspace) = workspace else {
|
||||
return Ok(Navigated::No);
|
||||
};
|
||||
|
||||
// TODO(andrew): respect preview tab settings
|
||||
// `enable_keep_preview_on_code_navigation` and
|
||||
// `enable_preview_file_from_code_navigation`
|
||||
workspace
|
||||
.update_in(cx, |workspace, window, cx| {
|
||||
workspace.open_resolved_path(path, window, cx)
|
||||
@@ -17108,10 +17108,6 @@ impl Editor {
|
||||
None => Ok(Navigated::No),
|
||||
}
|
||||
} else {
|
||||
let Some(workspace) = workspace else {
|
||||
return Ok(Navigated::No);
|
||||
};
|
||||
|
||||
let (target_buffer, target_ranges) = locations.into_iter().next().unwrap();
|
||||
let target_range = target_ranges.first().unwrap().clone();
|
||||
|
||||
@@ -17135,11 +17131,19 @@ impl Editor {
|
||||
workspace.active_pane().clone()
|
||||
};
|
||||
|
||||
let preview_tabs_settings = PreviewTabsSettings::get_global(cx);
|
||||
let keep_old_preview = preview_tabs_settings
|
||||
.enable_keep_preview_on_code_navigation;
|
||||
let allow_new_preview = preview_tabs_settings
|
||||
.enable_preview_file_from_code_navigation;
|
||||
|
||||
workspace.open_project_item(
|
||||
pane,
|
||||
target_buffer.clone(),
|
||||
true,
|
||||
true,
|
||||
keep_old_preview,
|
||||
allow_new_preview,
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
@@ -17416,11 +17420,14 @@ impl Editor {
|
||||
} else {
|
||||
format!("References to {target}")
|
||||
};
|
||||
let allow_preview = PreviewTabsSettings::get_global(cx)
|
||||
.enable_preview_multibuffer_from_code_navigation;
|
||||
Self::open_locations_in_multibuffer(
|
||||
workspace,
|
||||
locations,
|
||||
title,
|
||||
false,
|
||||
allow_preview,
|
||||
MultibufferSelectionMode::First,
|
||||
window,
|
||||
cx,
|
||||
@@ -17436,6 +17443,7 @@ impl Editor {
|
||||
locations: std::collections::HashMap<Entity<Buffer>, Vec<Range<Point>>>,
|
||||
title: String,
|
||||
split: bool,
|
||||
allow_preview: bool,
|
||||
multibuffer_selection_mode: MultibufferSelectionMode,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Workspace>,
|
||||
@@ -17483,6 +17491,7 @@ impl Editor {
|
||||
.is_some_and(|it| *it == key)
|
||||
})
|
||||
});
|
||||
let was_existing = existing.is_some();
|
||||
let editor = existing.unwrap_or_else(|| {
|
||||
cx.new(|cx| {
|
||||
let mut editor = Editor::for_multibuffer(
|
||||
@@ -17523,29 +17532,23 @@ impl Editor {
|
||||
});
|
||||
|
||||
let item = Box::new(editor);
|
||||
let item_id = item.item_id();
|
||||
|
||||
if split {
|
||||
let pane = workspace.adjacent_pane(window, cx);
|
||||
workspace.add_item(pane, item, None, true, true, window, cx);
|
||||
} else if PreviewTabsSettings::get_global(cx).enable_preview_from_code_navigation {
|
||||
let (preview_item_id, preview_item_idx) =
|
||||
workspace.active_pane().read_with(cx, |pane, _| {
|
||||
(pane.preview_item_id(), pane.preview_item_idx())
|
||||
});
|
||||
|
||||
workspace.add_item_to_active_pane(item, preview_item_idx, true, window, cx);
|
||||
|
||||
if let Some(preview_item_id) = preview_item_id {
|
||||
workspace.active_pane().update(cx, |pane, cx| {
|
||||
pane.remove_item(preview_item_id, false, false, window, cx);
|
||||
});
|
||||
}
|
||||
let pane = if split {
|
||||
workspace.adjacent_pane(window, cx)
|
||||
} else {
|
||||
workspace.add_item_to_active_pane(item, None, true, window, cx);
|
||||
}
|
||||
workspace.active_pane().update(cx, |pane, cx| {
|
||||
pane.set_preview_item_id(Some(item_id), cx);
|
||||
workspace.active_pane().clone()
|
||||
};
|
||||
let activate_pane = split;
|
||||
|
||||
let mut destination_index = None;
|
||||
pane.update(cx, |pane, cx| {
|
||||
if allow_preview && !was_existing {
|
||||
destination_index = pane.replace_preview_item_id(item.item_id(), window, cx);
|
||||
}
|
||||
if was_existing && !allow_preview {
|
||||
pane.unpreview_item_if_preview(item.item_id());
|
||||
}
|
||||
pane.add_item(item, activate_pane, true, destination_index, window, cx);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -20783,6 +20786,7 @@ impl Editor {
|
||||
locations,
|
||||
format!("Selections for '{title}'"),
|
||||
false,
|
||||
false,
|
||||
MultibufferSelectionMode::All,
|
||||
window,
|
||||
cx,
|
||||
@@ -22002,29 +22006,40 @@ impl Editor {
|
||||
// Handle file-less buffers separately: those are not really the project items, so won't have a project 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) =
|
||||
let (editor, pane_item_index, pane_item_id) =
|
||||
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))
|
||||
Some((editor, i, item.item_id()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})?;
|
||||
pane.update(cx, |pane, cx| {
|
||||
pane.activate_item(pane_item_index, true, true, window, cx)
|
||||
pane.activate_item(pane_item_index, true, true, window, cx);
|
||||
if !PreviewTabsSettings::get_global(cx)
|
||||
.enable_preview_from_multibuffer
|
||||
{
|
||||
pane.unpreview_item_if_preview(pane_item_id);
|
||||
}
|
||||
});
|
||||
Some(editor)
|
||||
})
|
||||
.flatten()
|
||||
.unwrap_or_else(|| {
|
||||
let keep_old_preview = PreviewTabsSettings::get_global(cx)
|
||||
.enable_keep_preview_on_code_navigation;
|
||||
let allow_new_preview =
|
||||
PreviewTabsSettings::get_global(cx).enable_preview_from_multibuffer;
|
||||
workspace.open_project_item::<Self>(
|
||||
pane.clone(),
|
||||
buffer,
|
||||
true,
|
||||
true,
|
||||
keep_old_preview,
|
||||
allow_new_preview,
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user