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.

project_panel: Honor preview setting for keyboard opens (#63758)

Chara1d25e83fe8f4
diff --git a/assets/settings/default.json b/assets/settings/default.json
index 63c16cf6d96..86ddd622432 100644
--- a/assets/settings/default.json
+++ b/assets/settings/default.json
@@ -1481,7 +1481,7 @@
// when you open another preview tab.
// This is useful for quickly viewing files without cluttering your workspace.
"enabled": true,
- // Whether to open tabs in preview mode when opened from the project panel with a single click.
+ // Whether to open tabs in preview mode when opened from the project panel with a single click or the Open action.
"enable_preview_from_project_panel": true,
// Whether to open tabs in preview mode when selected from the file finder.
"enable_preview_from_file_finder": false,
diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs
index ccf7a7dff94..26a263dcabe 100644
--- a/crates/project_panel/src/project_panel.rs
+++ b/crates/project_panel/src/project_panel.rs
@@ -1769,7 +1769,13 @@ impl ProjectPanel {
fn open(&mut self, _: &Open, window: &mut Window, cx: &mut Context<Self>) {
let preview_tabs_enabled =
PreviewTabsSettings::get_global(cx).enable_preview_from_project_panel;
- self.open_internal(true, !preview_tabs_enabled, None, window, cx);
+ self.open_internal(
+ preview_tabs_enabled,
+ !preview_tabs_enabled,
+ None,
+ window,
+ cx,
+ );
}
fn open_permanent(&mut self, _: &OpenPermanent, window: &mut Window, cx: &mut Context<Self>) {
diff --git a/crates/project_panel/src/project_panel_tests.rs b/crates/project_panel/src/project_panel_tests.rs
index f02b4c7fd7a..55fa3ea8672 100644
--- a/crates/project_panel/src/project_panel_tests.rs
+++ b/crates/project_panel/src/project_panel_tests.rs
@@ -174,6 +174,66 @@ async fn test_opening_file(cx: &mut gpui::TestAppContext) {
]
);
ensure_single_file_is_opened(&workspace, "test/second.rs", cx);
+
+ let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());
+ pane.read_with(cx, |pane, _| {
+ assert_eq!(pane.items_len(), 1);
+ let active_item = pane.active_item();
+ assert!(active_item.is_some());
+ assert_eq!(
+ pane.preview_item_id(),
+ active_item.map(|item| item.item_id())
+ );
+ });
+}
+
+#[gpui::test]
+async fn test_opening_file_with_project_panel_previews_disabled(cx: &mut gpui::TestAppContext) {
+ init_test_with_editor(cx);
+ cx.update(|cx| {
+ cx.update_global::<SettingsStore, _>(|store, cx| {
+ store.update_user_settings(cx, |settings| {
+ settings
+ .preview_tabs
+ .get_or_insert_default()
+ .enable_preview_from_project_panel = Some(false);
+ });
+ });
+ });
+
+ let fs = FakeFs::new(cx.executor());
+ fs.insert_tree(
+ path!("/src"),
+ json!({
+ "test": {
+ "first.rs": "// First Rust file",
+ "second.rs": "// Second Rust file",
+ }
+ }),
+ )
+ .await;
+
+ let project = Project::test(fs.clone(), [path!("/src").as_ref()], cx).await;
+ let window = cx.add_window(|window, cx| MultiWorkspace::test_new(project.clone(), window, cx));
+ let workspace = window
+ .read_with(cx, |multi_workspace, _| multi_workspace.workspace().clone())
+ .unwrap();
+ let cx = &mut VisualTestContext::from_window(window.into(), cx);
+ let panel = workspace.update_in(cx, ProjectPanel::new);
+ cx.run_until_parked();
+
+ toggle_expand_dir(&panel, "src/test", cx);
+ for path in ["src/test/first.rs", "src/test/second.rs"] {
+ select_path(&panel, path, cx);
+ panel.update_in(cx, |panel, window, cx| panel.open(&Open, window, cx));
+ cx.run_until_parked();
+ }
+
+ let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());
+ pane.read_with(cx, |pane, _| {
+ assert_eq!(pane.items_len(), 2);
+ assert_eq!(pane.preview_item_id(), None);
+ });
}
#[gpui::test]
diff --git a/crates/settings_content/src/workspace.rs b/crates/settings_content/src/workspace.rs
index 4e27a8d9a88..e38b9028c16 100644
--- a/crates/settings_content/src/workspace.rs
+++ b/crates/settings_content/src/workspace.rs
@@ -212,7 +212,8 @@ pub struct PreviewTabsSettingsContent {
///
/// Default: true
pub enabled: Option<bool>,
- /// Whether to open tabs in preview mode when opened from the project panel with a single click.
+ /// Whether to open tabs in preview mode when opened from the project panel
+ /// with a single click or the `project_panel::Open` action.
///
/// Default: true
pub enable_preview_from_project_panel: Option<bool>,
diff --git a/crates/settings_ui/src/page_data.rs b/crates/settings_ui/src/page_data.rs
index dea5732f0f3..da860a884a6 100644
--- a/crates/settings_ui/src/page_data.rs
+++ b/crates/settings_ui/src/page_data.rs
@@ -4810,7 +4810,7 @@ fn window_and_layout_page() -> SettingsPage {
}),
SettingsPageItem::SettingItem(SettingItem {
title: "Enable Preview From Project Panel",
- description: "Whether to open tabs in preview mode when opened from the project panel with a single click.",
+ description: "Whether to open tabs in preview mode when opened from the project panel with a single click or the Open action.",
field: Box::new(SettingField {
organization_override: None,
json_path: Some("preview_tabs.enable_preview_from_project_panel"),
diff --git a/docs/src/project-panel.md b/docs/src/project-panel.md
index 7c382a2b0cf..20ec2bf257a 100644
--- a/docs/src/project-panel.md
+++ b/docs/src/project-panel.md
@@ -24,6 +24,10 @@ permanent tab. Editing the file or double-clicking it promotes it to a permanent
Middle-clicking a file skips the preview and opens it in a permanent, focused tab
right away.
+Set [`preview_tabs.enable_preview_from_project_panel`](./reference/all-settings.md#enable-preview-from-project-panel)
+to `false` to open permanent tabs with a single click or {#action project_panel::Open}
+({#kb project_panel::Open}).
+
### Auto-reveal
By default, switching to a file in the editor will automatically highlight it in the
diff --git a/docs/src/reference/all-settings.md b/docs/src/reference/all-settings.md
index 124cf11a397..ae7830db707 100644
--- a/docs/src/reference/all-settings.md
+++ b/docs/src/reference/all-settings.md
@@ -3603,7 +3603,7 @@ Examples:
### Enable preview from project panel
-- Description: Determines whether to open files in preview mode when opened from the project panel with a single click.
+- Description: Determines whether to open files in preview mode when opened from the project panel with a single click or the {#action project_panel::Open} action ({#kb project_panel::Open}).
- Setting: `enable_preview_from_project_panel`
- Default: `true`