diff --git a/assets/settings/default.json b/assets/settings/default.json index d812673d9dac997df570625be3ea07cf1cb831dc..946e88c7237a747c5b24de7b6818e9ed0de614aa 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -768,6 +768,9 @@ // 5. Never show the scrollbar: // "never" "show": null, + // Whether to allow horizontal scrolling in the project panel. + // When false, the view is locked to the leftmost position and long file names are clipped. + "horizontal_scroll": true, }, // Which files containing diagnostic errors/warnings to mark in the project panel. // This setting can take the following three values: diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index 2984bb49c6a961c77adc1b82c806f7ec57d54a3e..96e680c0d1648bd4cf337cbc55e321e3948c217a 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -6341,6 +6341,7 @@ impl Render for ProjectPanel { let panel_settings = ProjectPanelSettings::get_global(cx); let indent_size = panel_settings.indent_size; let show_indent_guides = panel_settings.indent_guides.show == ShowIndentGuides::Always; + let horizontal_scroll = panel_settings.scrollbar.horizontal_scroll; let show_sticky_entries = { if panel_settings.sticky_scroll { let is_scrollable = self.scroll_handle.is_scrollable(); @@ -6713,10 +6714,14 @@ impl Render for ProjectPanel { }) }) .with_sizing_behavior(ListSizingBehavior::Infer) - .with_horizontal_sizing_behavior( - ListHorizontalSizingBehavior::Unconstrained, - ) - .with_width_from_item(self.state.max_width_item_index) + .with_horizontal_sizing_behavior(if horizontal_scroll { + ListHorizontalSizingBehavior::Unconstrained + } else { + ListHorizontalSizingBehavior::FitList + }) + .when(horizontal_scroll, |list| { + list.with_width_from_item(self.state.max_width_item_index) + }) .track_scroll(&self.scroll_handle), ) .child( @@ -6877,13 +6882,17 @@ impl Render for ProjectPanel { .size_full(), ) .custom_scrollbars( - Scrollbars::for_settings::() - .tracked_scroll_handle(&self.scroll_handle) - .with_track_along( - ScrollAxes::Horizontal, - cx.theme().colors().panel_background, - ) - .notify_content(), + { + let mut scrollbars = Scrollbars::for_settings::() + .tracked_scroll_handle(&self.scroll_handle); + if horizontal_scroll { + scrollbars = scrollbars.with_track_along( + ScrollAxes::Horizontal, + cx.theme().colors().panel_background, + ); + } + scrollbars.notify_content() + }, window, cx, ) diff --git a/crates/project_panel/src/project_panel_settings.rs b/crates/project_panel/src/project_panel_settings.rs index 0d703c55c06dfff2976fe59f6e030ad9eb1d758b..de2ff8e0087b8e7dbe4fcc533e3eea0470553b50 100644 --- a/crates/project_panel/src/project_panel_settings.rs +++ b/crates/project_panel/src/project_panel_settings.rs @@ -49,6 +49,11 @@ pub struct ScrollbarSettings { /// /// Default: inherits editor scrollbar settings pub show: Option, + /// Whether to allow horizontal scrolling in the project panel. + /// When false, the view is locked to the leftmost position and long file names are clipped. + /// + /// Default: true + pub horizontal_scroll: bool, } #[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)] @@ -111,8 +116,12 @@ impl Settings for ProjectPanelSettings { auto_fold_dirs: project_panel.auto_fold_dirs.unwrap(), bold_folder_labels: project_panel.bold_folder_labels.unwrap(), starts_open: project_panel.starts_open.unwrap(), - scrollbar: ScrollbarSettings { - show: project_panel.scrollbar.unwrap().show.map(Into::into), + scrollbar: { + let scrollbar = project_panel.scrollbar.unwrap(); + ScrollbarSettings { + show: scrollbar.show.map(Into::into), + horizontal_scroll: scrollbar.horizontal_scroll.unwrap(), + } }, show_diagnostics: project_panel.show_diagnostics.unwrap(), hide_root: project_panel.hide_root.unwrap(), diff --git a/crates/settings/src/vscode_import.rs b/crates/settings/src/vscode_import.rs index 8a5a497d265c02787d6944915c0dba56e2381a79..bcc579984bda0268a7405cbd1ea184cafc493aab 100644 --- a/crates/settings/src/vscode_import.rs +++ b/crates/settings/src/vscode_import.rs @@ -793,7 +793,12 @@ impl VsCodeSettings { hide_root: None, indent_guides: None, indent_size: None, - scrollbar: None, + scrollbar: self.read_bool("workbench.list.horizontalScrolling").map( + |horizontal_scrolling| ProjectPanelScrollbarSettingsContent { + show: None, + horizontal_scroll: Some(horizontal_scrolling), + }, + ), show_diagnostics: self .read_bool("problems.decorations.enabled") .and_then(|b| if b { Some(ShowDiagnostics::Off) } else { None }), diff --git a/crates/settings_content/src/workspace.rs b/crates/settings_content/src/workspace.rs index 7262a83b384665b0bcd868bf14dbfaa2928a35c1..92dc6679e60fc5d54b24afafa4daa00600c066f2 100644 --- a/crates/settings_content/src/workspace.rs +++ b/crates/settings_content/src/workspace.rs @@ -6,8 +6,8 @@ use serde::{Deserialize, Serialize}; use settings_macros::{MergeFrom, with_fallible_options}; use crate::{ - CenteredPaddingSettings, DelayMs, DockPosition, DockSide, InactiveOpacity, - ScrollbarSettingsContent, ShowIndentGuides, serialize_optional_f32_with_two_decimal_places, + CenteredPaddingSettings, DelayMs, DockPosition, DockSide, InactiveOpacity, ShowIndentGuides, + ShowScrollbar, serialize_optional_f32_with_two_decimal_places, }; #[with_fallible_options] @@ -710,7 +710,7 @@ pub struct ProjectPanelSettingsContent { /// Default: true pub starts_open: Option, /// Scrollbar-related settings - pub scrollbar: Option, + pub scrollbar: Option, /// Which files containing diagnostic errors/warnings to mark in the project panel. /// /// Default: all @@ -793,6 +793,23 @@ pub enum ProjectPanelSortMode { FilesFirst, } +#[with_fallible_options] +#[derive( + Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq, Default, +)] +pub struct ProjectPanelScrollbarSettingsContent { + /// When to show the scrollbar in the project panel. + /// + /// Default: inherits editor scrollbar settings + pub show: Option, + /// Whether to allow horizontal scrolling in the project panel. + /// When false, the view is locked to the leftmost position and + /// long file names are clipped. + /// + /// Default: true + pub horizontal_scroll: Option, +} + #[with_fallible_options] #[derive( Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq, Default, diff --git a/crates/settings_ui/src/page_data.rs b/crates/settings_ui/src/page_data.rs index 708840668d7502ae0c34e9f1751fd7b76da2ca07..9243e14521010c5b3aa2a9092c6e0a687a989306 100644 --- a/crates/settings_ui/src/page_data.rs +++ b/crates/settings_ui/src/page_data.rs @@ -4238,7 +4238,7 @@ fn window_and_layout_page() -> SettingsPage { } fn panels_page() -> SettingsPage { - fn project_panel_section() -> [SettingsPageItem; 22] { + fn project_panel_section() -> [SettingsPageItem; 23] { [ SettingsPageItem::SectionHeader("Project Panel"), SettingsPageItem::SettingItem(SettingItem { @@ -4516,6 +4516,32 @@ fn panels_page() -> SettingsPage { metadata: None, files: USER, }), + SettingsPageItem::SettingItem(SettingItem { + title: "Horizontal Scroll", + description: "Whether to allow horizontal scrolling in the project panel. When disabled, the view is always locked to the leftmost position and long file names are clipped.", + field: Box::new(SettingField { + json_path: Some("project_panel.scrollbar.horizontal_scroll"), + pick: |settings_content| { + settings_content + .project_panel + .as_ref()? + .scrollbar + .as_ref()? + .horizontal_scroll + .as_ref() + }, + write: |settings_content, value| { + settings_content + .project_panel + .get_or_insert_default() + .scrollbar + .get_or_insert_default() + .horizontal_scroll = value; + }, + }), + metadata: None, + files: USER, + }), SettingsPageItem::SettingItem(SettingItem { title: "Show Diagnostics", description: "Which files containing diagnostic errors/warnings to mark in the project panel.", diff --git a/docs/src/reference/all-settings.md b/docs/src/reference/all-settings.md index 32fec4a84d56cf996dc85cf112e4daec7893311b..7248a5636a29339ec2ca93481cfa4056b2527d30 100644 --- a/docs/src/reference/all-settings.md +++ b/docs/src/reference/all-settings.md @@ -4695,7 +4695,8 @@ Run the {#action theme_selector::Toggle} action in the command palette to see a "bold_folder_labels": false, "drag_and_drop": true, "scrollbar": { - "show": null + "show": null, + "horizontal_scroll": true }, "sticky_scroll": true, "show_diagnostics": "all", @@ -4941,9 +4942,9 @@ Run the {#action theme_selector::Toggle} action in the command palette to see a } ``` -### Scrollbar: Show +### Scrollbar -- Description: Whether to show a scrollbar in the project panel. Possible values: null, "auto", "system", "always", "never". Inherits editor settings when absent, see its description for more details. +- Description: Scrollbar-related settings for the project panel. - Setting: `scrollbar` - Default: @@ -4951,7 +4952,8 @@ Run the {#action theme_selector::Toggle} action in the command palette to see a { "project_panel": { "scrollbar": { - "show": null + "show": null, + "horizontal_scroll": true } } } @@ -4959,29 +4961,8 @@ Run the {#action theme_selector::Toggle} action in the command palette to see a **Options** -1. Show scrollbar in the project panel - -```json [settings] -{ - "project_panel": { - "scrollbar": { - "show": "always" - } - } -} -``` - -2. Hide scrollbar in the project panel - -```json [settings] -{ - "project_panel": { - "scrollbar": { - "show": "never" - } - } -} -``` +- `show`: Whether to show a scrollbar in the project panel. Possible values: null, "auto", "system", "always", "never". Inherits editor settings when absent, see its description for more details. +- `horizontal_scroll`: Whether to allow horizontal scrolling in the project panel. When `false`, the view is locked to the leftmost position and long file names are clipped. ### Sort Mode