Add minimap into the editor controls (#30285)

Follow-up of https://github.com/zed-industries/zed/pull/26893

Release Notes:

- N/A
This commit is contained in:
Kirill Bulatov 2025-05-08 20:58:24 +03:00 committed by GitHub
parent f21780cef3
commit 2b6280ad56
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 60 additions and 12 deletions

View file

@ -1407,7 +1407,7 @@ impl InlineAssistant {
enum DeletedLines {}
let mut editor = Editor::for_multibuffer(multi_buffer, None, window, cx);
editor.disable_scrollbars_and_minimap(cx);
editor.disable_scrollbars_and_minimap(window, cx);
editor.set_soft_wrap_mode(language::language_settings::SoftWrap::None, cx);
editor.set_show_wrap_guides(false, cx);
editor.set_show_gutter(false, cx);

View file

@ -226,7 +226,7 @@ impl ContextEditor {
let editor = cx.new(|cx| {
let mut editor =
Editor::for_buffer(context.read(cx).buffer().clone(), None, window, cx);
editor.disable_scrollbars_and_minimap(cx);
editor.disable_scrollbars_and_minimap(window, cx);
editor.set_soft_wrap_mode(SoftWrap::EditorWidth, cx);
editor.set_show_line_numbers(false, cx);
editor.set_show_git_diff_gutter(false, cx);

View file

@ -359,7 +359,7 @@ impl EditFileToolCard {
editor.set_show_gutter(false, cx);
editor.disable_inline_diagnostics();
editor.disable_expand_excerpt_buttons(cx);
editor.disable_scrollbars_and_minimap(cx);
editor.disable_scrollbars_and_minimap(window, cx);
editor.set_soft_wrap_mode(SoftWrap::None, cx);
editor.scroll_manager.set_forbid_vertical_scroll(true);
editor.set_show_indent_guides(false, cx);

View file

@ -431,6 +431,7 @@ actions!(
ToggleInlineDiagnostics,
ToggleEditPrediction,
ToggleLineNumbers,
ToggleMinimap,
SwapSelectionEnds,
SetMark,
ToggleRelativeLineNumbers,

View file

@ -6107,6 +6107,10 @@ impl Editor {
}
}
pub fn supports_minimap(&self) -> bool {
self.mode.is_full()
}
fn edit_predictions_enabled_in_buffer(
&self,
buffer: &Entity<Buffer>,
@ -15087,6 +15091,17 @@ impl Editor {
self.refresh_inline_diagnostics(false, window, cx);
}
pub fn toggle_minimap(
&mut self,
_: &ToggleMinimap,
window: &mut Window,
cx: &mut Context<Editor>,
) {
if self.supports_minimap() {
self.set_show_minimap(!self.show_minimap, window, cx);
}
}
fn refresh_inline_diagnostics(
&mut self,
debounce: bool,
@ -16544,14 +16559,27 @@ impl Editor {
cx.notify();
}
pub fn set_show_minimap(&mut self, show_minimap: bool, cx: &mut Context<Self>) {
self.show_minimap = show_minimap;
cx.notify();
pub fn set_show_minimap(
&mut self,
show_minimap: bool,
window: &mut Window,
cx: &mut Context<Self>,
) {
if self.show_minimap != show_minimap {
self.show_minimap = show_minimap;
if show_minimap {
let minimap_settings = EditorSettings::get_global(cx).minimap;
self.minimap = self.create_minimap(minimap_settings, window, cx);
} else {
self.minimap = None;
}
cx.notify();
}
}
pub fn disable_scrollbars_and_minimap(&mut self, cx: &mut Context<Self>) {
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, cx);
self.set_show_minimap(false, window, cx);
}
pub fn set_show_line_numbers(&mut self, show_line_numbers: bool, cx: &mut Context<Self>) {
@ -18045,8 +18073,8 @@ impl Editor {
}
let minimap_settings = EditorSettings::get_global(cx).minimap;
if self.minimap.as_ref().is_some() != minimap_settings.minimap_enabled() {
self.minimap = self.create_minimap(minimap_settings, window, cx);
if self.show_minimap != minimap_settings.minimap_enabled() {
self.set_show_minimap(!self.show_minimap, 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)

View file

@ -428,6 +428,7 @@ impl EditorElement {
register_action(editor, window, Editor::toggle_inlay_hints);
register_action(editor, window, Editor::toggle_edit_predictions);
register_action(editor, window, Editor::toggle_inline_diagnostics);
register_action(editor, window, Editor::toggle_minimap);
register_action(editor, window, hover_popover::hover);
register_action(editor, window, Editor::reveal_in_finder);
register_action(editor, window, Editor::copy_path);

View file

@ -101,6 +101,8 @@ 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 minimap_enabled = supports_minimap && editor_value.minimap().is_some();
let focus_handle = editor_value.focus_handle(cx);
@ -244,7 +246,6 @@ impl Render for QuickActionBar {
}
}
);
}
if supports_inline_diagnostics {
@ -270,6 +271,23 @@ impl Render for QuickActionBar {
);
}
if supports_minimap {
menu = menu.toggleable_entry("Minimap", minimap_enabled, IconPosition::Start, Some(editor::actions::ToggleMinimap.boxed_clone()), {
let editor = editor.clone();
move |window, cx| {
editor
.update(cx, |editor, cx| {
editor.toggle_minimap(
&editor::actions::ToggleMinimap,
window,
cx,
);
})
.ok();
}
},)
}
if has_edit_prediction_provider {
let mut inline_completion_entry = ContextMenuEntry::new("Edit Predictions")
.toggleable(IconPosition::Start, edit_predictions_enabled_at_cursor && show_edit_predictions)

View file

@ -275,7 +275,7 @@ impl RateCompletionModal {
completion,
feedback_editor: cx.new(|cx| {
let mut editor = Editor::multi_line(window, cx);
editor.disable_scrollbars_and_minimap(cx);
editor.disable_scrollbars_and_minimap(window, cx);
editor.set_soft_wrap_mode(language_settings::SoftWrap::EditorWidth, cx);
editor.set_show_line_numbers(false, cx);
editor.set_show_git_diff_gutter(false, cx);