Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

tab_switcher: Add setting to disable file preview (#56235)

sebascadpief376006f327
diff --git a/assets/settings/default.json b/assets/settings/default.json
index 29ef750de27..2ba29d6f92d 100644
--- a/assets/settings/default.json
+++ b/assets/settings/default.json
@@ -1475,6 +1475,13 @@
// When disabled, all tabs appear in a single row (default behavior).
"show_pinned_tabs_in_separate_row": false,
},
+ // Settings related to the tab switcher (Ctrl-Tab).
+ "tab_switcher": {
+ // When false, files are not shown while cycling through the tab switcher.
+ // Only the confirmed file (when the modifier key is released) is shown and
+ // recorded in the MRU history.
+ "show_file_preview": true,
+ },
// Settings related to the editor's tabs
"tabs": {
// Show git status colors in the editor tabs.
diff --git a/crates/settings/src/vscode_import.rs b/crates/settings/src/vscode_import.rs
index 8f6e81ec696..1b5c2fd660e 100644
--- a/crates/settings/src/vscode_import.rs
+++ b/crates/settings/src/vscode_import.rs
@@ -233,6 +233,7 @@ impl VsCodeSettings {
session: None,
status_bar: self.status_bar_settings_content(),
tab_bar: self.tab_bar_settings_content(),
+ tab_switcher: None,
tabs: self.item_settings_content(),
telemetry: self.telemetry_settings_content(),
terminal: self.terminal_settings_content(),
diff --git a/crates/settings_content/src/settings_content.rs b/crates/settings_content/src/settings_content.rs
index 88083da0ba8..c97679dfaee 100644
--- a/crates/settings_content/src/settings_content.rs
+++ b/crates/settings_content/src/settings_content.rs
@@ -202,6 +202,7 @@ pub struct SettingsContent {
pub tabs: Option<ItemSettingsContent>,
pub tab_bar: Option<TabBarSettingsContent>,
+ pub tab_switcher: Option<TabSwitcherSettingsContent>,
pub status_bar: Option<StatusBarSettingsContent>,
pub preview_tabs: Option<PreviewTabsSettingsContent>,
@@ -404,7 +405,7 @@ impl SettingsContent {
fallible_options::flattened_deserialize!(SettingsContent {
sections: { project, theme, extension, workspace, editor, remote },
options: {
- call_hierarchy, command_palette, file_finder, git_panel, tabs, tab_bar, status_bar, preview_tabs, agent,
+ call_hierarchy, command_palette, file_finder, git_panel, tabs, tab_bar, tab_switcher, status_bar, preview_tabs, agent,
agent_servers, audio, auto_update, base_keymap, collaboration_panel, debugger, diagnostics,
git,
global_lsp_settings, image_viewer, markdown_preview, repl, helix_mode, hide_mouse,
@@ -1505,6 +1506,17 @@ pub struct ReplSettingsContent {
pub output_max_height_lines: Option<usize>,
}
+/// Settings for configuring the tab switcher behaviour.
+#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
+pub struct TabSwitcherSettingsContent {
+ /// When false, files are not shown while cycling through the tab switcher.
+ /// Only the confirmed file (when the modifier key is released) is shown and
+ /// recorded in the MRU history.
+ ///
+ /// Default: true
+ pub show_file_preview: Option<bool>,
+}
+
/// Settings for configuring the which-key popup behaviour.
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
pub struct WhichKeySettingsContent {
diff --git a/crates/tab_switcher/src/tab_switcher.rs b/crates/tab_switcher/src/tab_switcher.rs
index 54e0a14449b..aa921dde3d0 100644
--- a/crates/tab_switcher/src/tab_switcher.rs
+++ b/crates/tab_switcher/src/tab_switcher.rs
@@ -15,7 +15,7 @@ use picker::{Picker, PickerDelegate};
use project::Project;
use schemars::JsonSchema;
use serde::Deserialize;
-use settings::Settings;
+use settings::{RegisterSetting, Settings, SettingsContent, TabSwitcherSettingsContent};
use std::{cmp::Reverse, sync::Arc};
use ui::{
DecoratedIcon, IconDecoration, IconDecorationKind, ListItem, ListItemSpacing, Tooltip,
@@ -28,6 +28,20 @@ use workspace::{
pane::{render_item_indicator, tab_details},
};
+#[derive(Clone, Copy, Debug, RegisterSetting)]
+pub struct TabSwitcherSettings {
+ pub show_file_preview: bool,
+}
+
+impl Settings for TabSwitcherSettings {
+ fn from_settings(content: &SettingsContent) -> Self {
+ let tab_switcher: &TabSwitcherSettingsContent = content.tab_switcher.as_ref().unwrap();
+ Self {
+ show_file_preview: tab_switcher.show_file_preview.unwrap(),
+ }
+ }
+}
+
const PANEL_WIDTH_REMS: f32 = 28.;
/// Toggles the tab switcher interface.
@@ -752,7 +766,7 @@ impl PickerDelegate for TabSwitcherDelegate {
) {
self.selected_index = ix;
- if !self.open_in_active_pane {
+ if !self.open_in_active_pane && TabSwitcherSettings::get_global(cx).show_file_preview {
let Some(selected_match) = self.matches.get(self.selected_index()) else {
return;
};
diff --git a/crates/tab_switcher/src/tab_switcher_tests.rs b/crates/tab_switcher/src/tab_switcher_tests.rs
index 29a4e8d9251..85c50effbbb 100644
--- a/crates/tab_switcher/src/tab_switcher_tests.rs
+++ b/crates/tab_switcher/src/tab_switcher_tests.rs
@@ -4,6 +4,7 @@ use gpui::{TestAppContext, VisualTestContext};
use menu::SelectPrevious;
use project::{Project, ProjectPath};
use serde_json::json;
+use settings::SettingsStore;
use util::{path, rel_path::rel_path};
use workspace::{ActivatePreviousItem, AppState, MultiWorkspace, Workspace, item::test::TestItem};
@@ -627,3 +628,50 @@ async fn test_toggle_all_stays_open_after_closing_last_tab_in_active_pane(
let _ = cx;
});
}
+
+#[gpui::test]
+async fn test_show_file_preview_false(cx: &mut gpui::TestAppContext) {
+ let app_state = init_test(cx);
+ app_state
+ .fs
+ .as_fake()
+ .insert_tree(
+ path!("/root"),
+ json!({
+ "1.txt": "First file",
+ "2.txt": "Second file",
+ }),
+ )
+ .await;
+
+ let project = Project::test(app_state.fs.clone(), [path!("/root").as_ref()], cx).await;
+ let (multi_workspace, cx) =
+ cx.add_window_view(|window, cx| MultiWorkspace::test_new(project.clone(), window, cx));
+ let workspace = multi_workspace.read_with(cx, |mw, _| mw.workspace().clone());
+
+ open_buffer("1.txt", &workspace, cx).await;
+ open_buffer("2.txt", &workspace, cx).await;
+
+ cx.update(|_window, cx| {
+ cx.update_global::<SettingsStore, _>(|store, cx| {
+ store.update_user_settings(cx, |settings| {
+ let tab_switcher = settings.tab_switcher.get_or_insert_with(Default::default);
+ tab_switcher.show_file_preview = Some(false);
+ });
+ });
+ });
+
+ cx.simulate_modifiers_change(Modifiers::control());
+ let _tab_switcher = open_tab_switcher(false, &workspace, cx);
+ cx.read(|cx| {
+ let active = workspace.read(cx).active_item_as::<Editor>(cx).unwrap();
+ assert_eq!(active.read(cx).title(cx), "2.txt");
+ });
+
+ cx.simulate_modifiers_change(Modifiers::none());
+ cx.read(|cx| {
+ let active = workspace.read(cx).active_item_as::<Editor>(cx).unwrap();
+ assert_eq!(active.read(cx).title(cx), "1.txt");
+ });
+ assert_tab_switcher_is_closed(workspace, cx);
+}