From 4bbb7b5c2f84a8f5129c1fbf5eb8db21ae7f9f56 Mon Sep 17 00:00:00 2001 From: Alvaro Parker <64918109+AlvaroParker@users.noreply.github.com> Date: Tue, 17 Jun 2025 09:39:49 -0400 Subject: [PATCH] Add setting for minimap on active editor only (#31390) Release Notes: - Add a setting to show the minimap only on the current active editor (file) - This can be configured on `settings.json`: ```json { "minimap": { "display_in": "active_editor", // defaults to "all_editors" } } ``` - The minimap won't hide if you go from an editor pane to the terminal, the project panel, the search bar, etc. It will only hide if you go from one editor pane to another. Preview: ![image](https://github.com/user-attachments/assets/87b476a2-148b-497e-9e97-ea390c545c87) Only the active editor (left) displays the minimap. --- assets/settings/default.json | 7 +++++++ crates/editor/src/editor_settings.rs | 24 ++++++++++++++++++++++++ crates/editor/src/element.rs | 13 +++++++++++++ 3 files changed, 44 insertions(+) diff --git a/assets/settings/default.json b/assets/settings/default.json index 1f1a1795c3..a1420a9aee 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -400,6 +400,13 @@ // 3. Never show the minimap: // "never" (default) "show": "never", + // Where to show the minimap in the editor. + // This setting can take two values: + // 1. Show the minimap on the focused editor only: + // "active_editor" + // 2. Show the minimap on all open editors: + // "all_editors" (default) + "display_in": "all_editors", // When to show the minimap thumb. // This setting can take two values: // 1. Show the minimap thumb if the mouse is over the minimap: diff --git a/crates/editor/src/editor_settings.rs b/crates/editor/src/editor_settings.rs index 44e220f90d..df859a03e8 100644 --- a/crates/editor/src/editor_settings.rs +++ b/crates/editor/src/editor_settings.rs @@ -130,6 +130,7 @@ pub struct Scrollbar { #[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)] pub struct Minimap { pub show: ShowMinimap, + pub display_in: DisplayIn, pub thumb: MinimapThumb, pub thumb_border: MinimapThumbBorder, pub current_line_highlight: Option, @@ -140,6 +141,11 @@ impl Minimap { self.show != ShowMinimap::Never } + #[inline] + pub fn on_active_editor(&self) -> bool { + self.display_in == DisplayIn::ActiveEditor + } + pub fn with_show_override(self) -> Self { Self { show: ShowMinimap::Always, @@ -189,6 +195,19 @@ pub enum ShowMinimap { Never, } +/// Where to show the minimap in the editor. +/// +/// Default: all_editors +#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)] +#[serde(rename_all = "snake_case")] +pub enum DisplayIn { + /// Show on all open editors. + #[default] + AllEditors, + /// Show the minimap on the active editor only. + ActiveEditor, +} + /// When to show the minimap thumb. /// /// Default: always @@ -573,6 +592,11 @@ pub struct MinimapContent { /// Default: never pub show: Option, + /// Where to show the minimap in the editor. + /// + /// Default: all_editors + pub display_in: Option, + /// When to show the minimap thumb. /// /// Default: always diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 7d81d7f4e2..b08c0d6bdc 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -1777,6 +1777,19 @@ impl EditorElement { let minimap_settings = EditorSettings::get_global(cx).minimap; + if minimap_settings.on_active_editor() { + let active_editor = self.editor.read(cx).workspace().and_then(|ws| { + ws.read(cx) + .active_pane() + .read(cx) + .active_item() + .and_then(|i| i.act_as::(cx)) + }); + if active_editor.is_some_and(|e| e != self.editor) { + return None; + } + } + if !snapshot.mode.is_full() || minimap_width.is_zero() || matches!(