From f3192b6fa6ccfd2335f041776981166c45ecdf03 Mon Sep 17 00:00:00 2001 From: Andrew Lygin Date: Tue, 16 Apr 2024 10:21:22 +0300 Subject: [PATCH] Fix scrollbar marker settings (#10530) Zed displays scrollbar markers of three types: git diffs, background highlights and diagnostics. At the moment, the "background highlights" markers are displayed for all the supported highlights: - Occurences of the symbol under cursor. - Search results. - Scope boundaries (only works when a symbol is selected). - Active hover popover position. They all use the same color, which leads to confusing results. For instance, in the following case I expect to see markers for the `new_anchor` occurences in lines 43 and 47. But besides them, there're also scope-markers for `ScrollAnchor` initialization block in lines 46 and 49, which makes me think that there're four places where `new_anchor` appears. zed-scrollbar-markers Existing settings `selection` and `symbol_selection` in the `scrollbar` section [don't work as expected](https://github.com/zed-industries/zed/pull/10080#discussion_r1552325493), which increases confusion. This PR only leaves two types of bg-highlight-markers and provides dedicated settings for them: - Occurences of the symbol under cursor. Setting: `selected_symbol`, default is `true`. - Search results. Setting: `search_results`, default is `true`. The `selection` and `symbol_selection` settings are not used anymore. Release Notes: - Breaking changes. Settings `selection` and `symbol_selection` in the `scrollbar` section renamed to `search_results` and `selected_symbol` respectively. Fixed the effect of these settings on which markers are displayed on the scrollbar. Optionally, include screenshots / media showcasing your addition that can be included in the release notes. - N/A /cc @mrnugget --- assets/settings/default.json | 8 +-- crates/editor/src/editor_settings.rs | 12 ++-- crates/editor/src/element.rs | 20 +++--- docs/src/configuring_zed.md | 96 ++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+), 18 deletions(-) diff --git a/assets/settings/default.json b/assets/settings/default.json index 0fb494a07d08c78e9569b396471a310781b9c1ac..b425e54ee69477cf0b3134408de62fb54c344079 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -145,10 +145,10 @@ "show": "auto", // Whether to show git diff indicators in the scrollbar. "git_diff": true, - // Whether to show selections in the scrollbar. - "selections": true, - // Whether to show symbols selections in the scrollbar. - "symbols_selections": true, + // Whether to show buffer search results in the scrollbar. + "search_results": true, + // Whether to show selected symbol occurrences in the scrollbar. + "selected_symbol": true, // Whether to show diagnostic indicators in the scrollbar. "diagnostics": true }, diff --git a/crates/editor/src/editor_settings.rs b/crates/editor/src/editor_settings.rs index 801044083af548d64a43eb4bf5a03665f54c2da5..20a9ea64e99c433f590b9c6b1a8b27b307540057 100644 --- a/crates/editor/src/editor_settings.rs +++ b/crates/editor/src/editor_settings.rs @@ -58,8 +58,8 @@ pub struct Toolbar { pub struct Scrollbar { pub show: ShowScrollbar, pub git_diff: bool, - pub selections: bool, - pub symbols_selections: bool, + pub selected_symbol: bool, + pub search_results: bool, pub diagnostics: bool, } @@ -194,14 +194,14 @@ pub struct ScrollbarContent { /// /// Default: true pub git_diff: Option, - /// Whether to show buffer search result markers in the scrollbar. + /// Whether to show buffer search result indicators in the scrollbar. /// /// Default: true - pub selections: Option, - /// Whether to show symbols highlighted markers in the scrollbar. + pub search_results: Option, + /// Whether to show selected symbol occurrences in the scrollbar. /// /// Default: true - pub symbols_selections: Option, + pub selected_symbol: Option, /// Whether to show diagnostic indicators in the scrollbar. /// /// Default: true diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 0c22c9dcefaaa4a235927b7998eada28c1afc38e..b30dd0ed9cd0c7bf3e83e791536d8f4ad444a20a 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -965,11 +965,11 @@ impl EditorElement { // Git (is_singleton && scrollbar_settings.git_diff && snapshot.buffer_snapshot.has_git_diffs()) || - // Selections - (is_singleton && scrollbar_settings.selections && editor.has_background_highlights::()) + // Buffer Search Results + (is_singleton && scrollbar_settings.search_results && editor.has_background_highlights::()) || - // Symbols Selections - (is_singleton && scrollbar_settings.symbols_selections && (editor.has_background_highlights::() || editor.has_background_highlights::())) + // Selected Symbol Occurrences + (is_singleton && scrollbar_settings.selected_symbol && (editor.has_background_highlights::() || editor.has_background_highlights::())) || // Diagnostics (is_singleton && scrollbar_settings.diagnostics && snapshot.buffer_snapshot.has_diagnostics()) @@ -2620,10 +2620,14 @@ impl EditorElement { for (background_highlight_id, (_, background_ranges)) in background_highlights.iter() { - if (*background_highlight_id - == TypeId::of::() - && scrollbar_settings.selections) - || scrollbar_settings.symbols_selections + let is_search_highlights = *background_highlight_id + == TypeId::of::(); + let is_symbol_occurrences = *background_highlight_id + == TypeId::of::() + || *background_highlight_id + == TypeId::of::(); + if (is_search_highlights && scrollbar_settings.search_results) + || (is_symbol_occurrences && scrollbar_settings.selected_symbol) { let marker_row_ranges = background_ranges.into_iter().map(|range| { diff --git a/docs/src/configuring_zed.md b/docs/src/configuring_zed.md index bbaca79953c2749cc4671828270d8ad9e26ad55a..9ef0930280e7a045b4e444be0b9aac025759a350 100644 --- a/docs/src/configuring_zed.md +++ b/docs/src/configuring_zed.md @@ -190,6 +190,102 @@ List of `string` values 2. Position the dock to the right of the workspace like a side panel: `right` 3. Position the dock full screen over the entire workspace: `expanded` +## Editor Scrollbar + +- Description: Whether or not to show the editor scrollbar and various elements in it. +- Setting: `scrollbar` +- Default: + +```json +"scrollbar": { + "show": "auto", + "git_diff": true, + "search_results": true, + "selected_symbol": true, + "diagnostics": true +}, +``` + +### Show Mode + +- Description: When to show the editor scrollbar. +- Setting: `show` +- Default: `auto` + +**Options** + +1. Show the scrollbar if there's important information or follow the system's configured behavior: + +```json +"scrollbar": { + "show": "auto" +} +``` + +2. Match the system's configured behavior: + +```json +"scrollbar": { + "show": "system" +} +``` + +3. Always show the scrollbar: + +```json +"scrollbar": { + "show": "always" +} +``` + +4. Never show the scrollbar: + +```json +"scrollbar": { + "show": "never" +} +``` + +### Git Diff Indicators + +- Description: Whether to show git diff indicators in the scrollbar. +- Setting: `git_diff` +- Default: `true` + +**Options** + +`boolean` values + +### Search Results Indicators + +- Description: Whether to show buffer search results in the scrollbar. +- Setting: `search_results` +- Default: `true` + +**Options** + +`boolean` values + +### Selected Symbols Indicators + +- Description: Whether to show selected symbol occurrences in the scrollbar. +- Setting: `selected_symbol` +- Default: `true` + +**Options** + +`boolean` values + +### Diagnostics + +- Description: Whether to show diagnostic indicators in the scrollbar. +- Setting: `diagnostics` +- Default: `true` + +**Options** + +`boolean` values + ## Editor Toolbar - Description: Whether or not to show various elements in the editor toolbar.