editor: Ensure minimap is shown when show_minimap
is toggled to true
(#30326)
Follow-up of #30285 This PR ensures the action added in the linked PR also works when the user does not have the minimap enabled via settings. Currently, the toggle only works when the user has already enabled the minimap in their settings. This happens because inb4fbb9bc08/crates/editor/src/element.rs (L7160-L7164)
as well asb4fbb9bc08/crates/editor/src/element.rs (L1542)
we check for the user configuration before reserving space for the minimap as well as layouting it and because inb4fbb9bc08/crates/editor/src/editor.rs (L16404)
withb4fbb9bc08/crates/editor/src/editor_settings.rs (L132-L134)
we would not even create a minimap when the user disabled it via their settings. --- This PR fixes this by ensuring a minimap is created on the toggle issue as well as lifting some of the restrictions. Since we are always only returning a minimap inb4fbb9bc08/crates/editor/src/editor.rs (L16443-L16445)
when `show_minimap` is set to `true`, we can assume in the rendering code that if a minimap is present, it should be layouted and rendered no matter if `ShowMinimap` is currently set to `Never`. We can do this since `show_minimap` always reflects the current user configuration, seeb4fbb9bc08/crates/editor/src/editor.rs (L18163-L18164)
I also removed the minimap deletion/recreation on the toggling of `show_minimap`, since this is not really needed - once we have stored a minimap editor within the editor, `show_minimap` is sufficient to ensure that it is only shown when the user requests it. Notice that we still will never create a minimap unless neccesary. Lastly, I updated the `supports_minimap` check to account for the fact that the minimap is currently disabled entirely for multibuffers. --- One thing I ~~did not tackle here~~ tackled in the second commit is that due to `show_minimap` now being exposed to the user, it is possible to enable the minimap for all full mode editors, e.g. the agent text thread editor <img width="592" alt="grafik" src="https://github.com/user-attachments/assets/5f6c0e8b-45f9-44e8-9625-9d51c1480f98" /> which should most likely not be possible when the minimap is programmatically disabled. Release Notes: - N/A
This commit is contained in:
parent
29c31f020e
commit
1ecd00a113
4 changed files with 72 additions and 24 deletions
|
@ -137,7 +137,7 @@ pub use proposed_changes_editor::{
|
|||
ProposedChangeLocation, ProposedChangesEditor, ProposedChangesEditorToolbar,
|
||||
};
|
||||
use smallvec::smallvec;
|
||||
use std::{cell::OnceCell, iter::Peekable};
|
||||
use std::{cell::OnceCell, iter::Peekable, ops::Not};
|
||||
use task::{ResolvedTask, RunnableTag, TaskTemplate, TaskVariables};
|
||||
|
||||
pub use lsp::CompletionContext;
|
||||
|
@ -184,7 +184,7 @@ use std::{
|
|||
cmp::{self, Ordering, Reverse},
|
||||
mem,
|
||||
num::NonZeroU32,
|
||||
ops::{ControlFlow, Deref, DerefMut, Not as _, Range, RangeInclusive},
|
||||
ops::{ControlFlow, Deref, DerefMut, Range, RangeInclusive},
|
||||
path::{Path, PathBuf},
|
||||
rc::Rc,
|
||||
time::{Duration, Instant},
|
||||
|
@ -711,6 +711,43 @@ impl ScrollbarMarkerState {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
pub enum MinimapVisibility {
|
||||
Disabled,
|
||||
Enabled(bool),
|
||||
}
|
||||
|
||||
impl MinimapVisibility {
|
||||
fn for_mode(mode: &EditorMode, cx: &App) -> Self {
|
||||
if mode.is_full() {
|
||||
Self::Enabled(EditorSettings::get_global(cx).minimap.minimap_enabled())
|
||||
} else {
|
||||
Self::Disabled
|
||||
}
|
||||
}
|
||||
|
||||
fn disabled(&self) -> bool {
|
||||
match *self {
|
||||
Self::Disabled => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn visible(&self) -> bool {
|
||||
match *self {
|
||||
Self::Enabled(visible) => visible,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn toggle_visibility(&self) -> Self {
|
||||
match *self {
|
||||
Self::Enabled(visible) => Self::Enabled(!visible),
|
||||
Self::Disabled => Self::Disabled,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct RunnableTasks {
|
||||
templates: Vec<(TaskSourceKind, TaskTemplate)>,
|
||||
|
@ -883,7 +920,7 @@ pub struct Editor {
|
|||
show_breadcrumbs: bool,
|
||||
show_gutter: bool,
|
||||
show_scrollbars: bool,
|
||||
show_minimap: bool,
|
||||
minimap_visibility: MinimapVisibility,
|
||||
disable_expand_excerpt_buttons: bool,
|
||||
show_line_numbers: Option<bool>,
|
||||
use_relative_line_numbers: Option<bool>,
|
||||
|
@ -1721,7 +1758,7 @@ impl Editor {
|
|||
blink_manager: blink_manager.clone(),
|
||||
show_local_selections: true,
|
||||
show_scrollbars: full_mode,
|
||||
show_minimap: full_mode,
|
||||
minimap_visibility: MinimapVisibility::for_mode(&mode, cx),
|
||||
show_breadcrumbs: EditorSettings::get_global(cx).toolbar.breadcrumbs,
|
||||
show_gutter: mode.is_full(),
|
||||
show_line_numbers: None,
|
||||
|
@ -6138,8 +6175,8 @@ impl Editor {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn supports_minimap(&self) -> bool {
|
||||
self.mode.is_full()
|
||||
pub fn supports_minimap(&self, cx: &App) -> bool {
|
||||
!self.minimap_visibility.disabled() && self.is_singleton(cx)
|
||||
}
|
||||
|
||||
fn edit_predictions_enabled_in_buffer(
|
||||
|
@ -15169,8 +15206,8 @@ impl Editor {
|
|||
window: &mut Window,
|
||||
cx: &mut Context<Editor>,
|
||||
) {
|
||||
if self.supports_minimap() {
|
||||
self.set_show_minimap(!self.show_minimap, window, cx);
|
||||
if self.supports_minimap(cx) {
|
||||
self.set_minimap_visibility(self.minimap_visibility.toggle_visibility(), window, cx);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16441,7 +16478,9 @@ impl Editor {
|
|||
}
|
||||
|
||||
pub fn minimap(&self) -> Option<&Entity<Self>> {
|
||||
self.minimap.as_ref().filter(|_| self.show_minimap)
|
||||
self.minimap
|
||||
.as_ref()
|
||||
.filter(|_| self.minimap_visibility.visible())
|
||||
}
|
||||
|
||||
pub fn wrap_guides(&self, cx: &App) -> SmallVec<[(usize, bool); 2]> {
|
||||
|
@ -16638,27 +16677,26 @@ impl Editor {
|
|||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn set_show_minimap(
|
||||
pub fn set_minimap_visibility(
|
||||
&mut self,
|
||||
show_minimap: bool,
|
||||
minimap_visibility: MinimapVisibility,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
if self.show_minimap != show_minimap {
|
||||
self.show_minimap = show_minimap;
|
||||
if show_minimap {
|
||||
if self.minimap_visibility != minimap_visibility {
|
||||
if minimap_visibility.visible() && self.minimap.is_none() {
|
||||
let minimap_settings = EditorSettings::get_global(cx).minimap;
|
||||
self.minimap = self.create_minimap(minimap_settings, window, cx);
|
||||
} else {
|
||||
self.minimap = None;
|
||||
self.minimap =
|
||||
self.create_minimap(minimap_settings.with_show_override(), window, cx);
|
||||
}
|
||||
self.minimap_visibility = minimap_visibility;
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn disable_scrollbars_and_minimap(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
self.set_show_scrollbars(false, cx);
|
||||
self.set_show_minimap(false, window, cx);
|
||||
self.set_minimap_visibility(MinimapVisibility::Disabled, window, cx);
|
||||
}
|
||||
|
||||
pub fn set_show_line_numbers(&mut self, show_line_numbers: bool, cx: &mut Context<Self>) {
|
||||
|
@ -18160,8 +18198,12 @@ impl Editor {
|
|||
}
|
||||
|
||||
let minimap_settings = EditorSettings::get_global(cx).minimap;
|
||||
if self.show_minimap != minimap_settings.minimap_enabled() {
|
||||
self.set_show_minimap(!self.show_minimap, window, cx);
|
||||
if self.minimap_visibility.visible() != minimap_settings.minimap_enabled() {
|
||||
self.set_minimap_visibility(
|
||||
self.minimap_visibility.toggle_visibility(),
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
} else if let Some(minimap_entity) = self.minimap.as_ref() {
|
||||
minimap_entity.update(cx, |minimap_editor, cx| {
|
||||
minimap_editor.update_minimap_configuration(minimap_settings, cx)
|
||||
|
|
|
@ -132,6 +132,13 @@ impl Minimap {
|
|||
pub fn minimap_enabled(&self) -> bool {
|
||||
self.show != ShowMinimap::Never
|
||||
}
|
||||
|
||||
pub fn with_show_override(self) -> Self {
|
||||
Self {
|
||||
show: ShowMinimap::Always,
|
||||
..self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
|
||||
|
|
|
@ -1539,7 +1539,7 @@ impl EditorElement {
|
|||
|| minimap_width.is_zero()
|
||||
|| matches!(
|
||||
minimap_settings.show,
|
||||
ShowMinimap::Never | ShowMinimap::Auto if scrollbar_layout.is_none_or(|layout| !layout.visible)
|
||||
ShowMinimap::Auto if scrollbar_layout.is_none_or(|layout| !layout.visible)
|
||||
)
|
||||
{
|
||||
return None;
|
||||
|
@ -7161,11 +7161,10 @@ impl Element for EditorElement {
|
|||
.editor
|
||||
.read_with(cx, |editor, _| editor.minimap().is_some())
|
||||
.then(|| match settings.minimap.show {
|
||||
ShowMinimap::Never => None,
|
||||
ShowMinimap::Always => Some(MinimapLayout::MINIMAP_WIDTH),
|
||||
ShowMinimap::Auto => {
|
||||
scrollbars_shown.then_some(MinimapLayout::MINIMAP_WIDTH)
|
||||
}
|
||||
_ => Some(MinimapLayout::MINIMAP_WIDTH),
|
||||
})
|
||||
.flatten()
|
||||
.filter(|minimap_width| {
|
||||
|
|
|
@ -105,7 +105,7 @@ impl Render for QuickActionBar {
|
|||
let show_edit_predictions = editor_value.edit_predictions_enabled();
|
||||
let edit_predictions_enabled_at_cursor =
|
||||
editor_value.edit_predictions_enabled_at_cursor(cx);
|
||||
let supports_minimap = editor_value.supports_minimap();
|
||||
let supports_minimap = editor_value.supports_minimap(cx);
|
||||
let minimap_enabled = supports_minimap && editor_value.minimap().is_some();
|
||||
|
||||
let focus_handle = editor_value.focus_handle(cx);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue