From ae3394f4decb8ea5cfb305d2faf9bb7ebec86044 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Wed, 17 May 2023 14:09:26 -0700 Subject: [PATCH 1/3] Add scrollbars setting --- assets/settings/default.json | 11 +++++++++++ crates/editor/src/editor.rs | 9 +++++++++ crates/editor/src/element.rs | 10 +++++++++- crates/settings/src/settings.rs | 15 +++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/assets/settings/default.json b/assets/settings/default.json index 20d07acae0..05e79ae9cc 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -43,6 +43,17 @@ // 3. Draw all invisible symbols: // "all" "show_whitespaces": "selection", + // Whether to show the scrollbar in the editor. + // This setting can take four values: + // + // 1. Show the scrollbar if there's important information or + // follow the system's configured behavior (default): + // "auto" + // 2. Match the system's configured behavior: + // "system" + // 3. Always show the scrollbar: + // "always" + "show_scrollbars": "auto", // Whether the screen sharing icon is shown in the os status bar. "show_call_status_icon": true, // Whether to use language servers to provide code intelligence. diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 21d495d6ee..218daf08c4 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -516,6 +516,15 @@ pub struct EditorSnapshot { ongoing_scroll: OngoingScroll, } +impl EditorSnapshot { + fn has_scrollbar_info(&self) -> bool { + self.buffer_snapshot + .git_diff_hunks_in_range(0..self.max_point().row(), false) + .next() + .is_some() + } +} + #[derive(Clone, Debug)] struct SelectionHistoryEntry { selections: Arc<[Selection]>, diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 1d4aff39de..e5fcb024c6 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -2058,7 +2058,15 @@ impl Element for EditorElement { )); } - let show_scrollbars = editor.scroll_manager.scrollbars_visible(); + let show_scrollbars = match cx.global::().show_scrollbars { + settings::ShowScrollbars::Auto => { + snapshot.has_scrollbar_info() + || editor.scroll_manager.scrollbars_visible() + } + settings::ShowScrollbars::System => editor.scroll_manager.scrollbars_visible(), + settings::ShowScrollbars::Always => true, + }; + let include_root = editor .project .as_ref() diff --git a/crates/settings/src/settings.rs b/crates/settings/src/settings.rs index 7ba52fcb5e..284d2579a5 100644 --- a/crates/settings/src/settings.rs +++ b/crates/settings/src/settings.rs @@ -46,6 +46,7 @@ pub struct Settings { pub hover_popover_enabled: bool, pub show_completions_on_input: bool, pub show_call_status_icon: bool, + pub show_scrollbars: ShowScrollbars, pub vim_mode: bool, pub autosave: Autosave, pub default_dock_anchor: DockAnchor, @@ -68,6 +69,15 @@ pub struct Settings { pub base_keymap: BaseKeymap, } +#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Default)] +#[serde(rename_all = "snake_case")] +pub enum ShowScrollbars { + #[default] + Auto, + System, + Always, +} + #[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Default)] pub enum BaseKeymap { #[default] @@ -390,6 +400,8 @@ pub struct SettingsFileContent { #[serde(default)] pub active_pane_magnification: Option, #[serde(default)] + pub show_scrollbars: Option, + #[serde(default)] pub cursor_blink: Option, #[serde(default)] pub confirm_quit: Option, @@ -547,6 +559,7 @@ impl Settings { features: Features { copilot: defaults.features.copilot.unwrap(), }, + show_scrollbars: defaults.show_scrollbars.unwrap(), } } @@ -598,6 +611,7 @@ impl Settings { merge(&mut self.autosave, data.autosave); merge(&mut self.default_dock_anchor, data.default_dock_anchor); merge(&mut self.base_keymap, data.base_keymap); + merge(&mut self.show_scrollbars, data.show_scrollbars); merge(&mut self.features.copilot, data.features.copilot); if let Some(copilot) = data.copilot { @@ -830,6 +844,7 @@ impl Settings { auto_update: true, base_keymap: Default::default(), features: Features { copilot: true }, + show_scrollbars: Default::default(), } } From 6cf439e73412bf332bfe358b845770d3f4813f78 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Wed, 17 May 2023 14:12:04 -0700 Subject: [PATCH 2/3] fmt --- crates/editor/src/element.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index e5fcb024c6..755c3091cb 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -2060,8 +2060,7 @@ impl Element for EditorElement { let show_scrollbars = match cx.global::().show_scrollbars { settings::ShowScrollbars::Auto => { - snapshot.has_scrollbar_info() - || editor.scroll_manager.scrollbars_visible() + snapshot.has_scrollbar_info() || editor.scroll_manager.scrollbars_visible() } settings::ShowScrollbars::System => editor.scroll_manager.scrollbars_visible(), settings::ShowScrollbars::Always => true, From f4e99ecde4cd6c57c6e317f4ba5ccbcea6affcb9 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Wed, 17 May 2023 14:19:35 -0700 Subject: [PATCH 3/3] Add never option to scrollbar settings --- assets/settings/default.json | 2 ++ crates/editor/src/element.rs | 1 + crates/settings/src/settings.rs | 1 + 3 files changed, 4 insertions(+) diff --git a/assets/settings/default.json b/assets/settings/default.json index 05e79ae9cc..1395edca4a 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -53,6 +53,8 @@ // "system" // 3. Always show the scrollbar: // "always" + // 4. Never show the scrollbar: + // "never" "show_scrollbars": "auto", // Whether the screen sharing icon is shown in the os status bar. "show_call_status_icon": true, diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 755c3091cb..e1e38f2e24 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -2064,6 +2064,7 @@ impl Element for EditorElement { } settings::ShowScrollbars::System => editor.scroll_manager.scrollbars_visible(), settings::ShowScrollbars::Always => true, + settings::ShowScrollbars::Never => false, }; let include_root = editor diff --git a/crates/settings/src/settings.rs b/crates/settings/src/settings.rs index 284d2579a5..55598845c7 100644 --- a/crates/settings/src/settings.rs +++ b/crates/settings/src/settings.rs @@ -76,6 +76,7 @@ pub enum ShowScrollbars { Auto, System, Always, + Never, } #[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Default)]