Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
indent guides: Toggle action (#12203)
Bennet Bo Fenner58a3ba02c629
diff --git a/crates/editor/src/actions.rs b/crates/editor/src/actions.rsindex feeb6f9357a..1c44ccc6f31 100644--- a/crates/editor/src/actions.rs+++ b/crates/editor/src/actions.rs@@ -273,6 +273,7 @@ gpui::actions!(ToggleHunkDiff,ToggleInlayHints,ToggleLineNumbers,+ ToggleIndentGuides,ToggleSoftWrap,Transpose,Undo,diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex e2b0f78d790..1d75d41075f 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -9640,6 +9640,22 @@ impl Editor {cx.notify();}+ pub fn toggle_indent_guides(&mut self, _: &ToggleIndentGuides, cx: &mut ViewContext<Self>) {+ let currently_enabled = self.should_show_indent_guides(cx);+ self.show_indent_guides = Some(!currently_enabled);+ cx.notify();+ }++ fn should_show_indent_guides(&self, cx: &mut ViewContext<Self>) -> bool {+ self.show_indent_guides.unwrap_or_else(|| {+ self.buffer+ .read(cx)+ .settings_at(0, cx)+ .indent_guides+ .enabled+ })+ }+pub fn toggle_line_numbers(&mut self, _: &ToggleLineNumbers, cx: &mut ViewContext<Self>) {let mut editor_settings = EditorSettings::get_global(cx).clone();editor_settings.gutter.line_numbers = !editor_settings.gutter.line_numbers;diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rsindex 8379451c40b..7d6e05c2638 100644--- a/crates/editor/src/element.rs+++ b/crates/editor/src/element.rs@@ -318,6 +318,7 @@ impl EditorElement {register_action(view, cx, Editor::open_excerpts_in_split);register_action(view, cx, Editor::toggle_soft_wrap);register_action(view, cx, Editor::toggle_line_numbers);+ register_action(view, cx, Editor::toggle_indent_guides);register_action(view, cx, Editor::toggle_inlay_hints);register_action(view, cx, hover_popover::hover);register_action(view, cx, Editor::reveal_in_finder);@@ -1473,10 +1474,9 @@ impl EditorElement {snapshot: &DisplaySnapshot,cx: &mut WindowContext,) -> Option<Vec<IndentGuideLayout>> {- let indent_guides =- self.editor- .read(cx)- .indent_guides(visible_buffer_range, snapshot, cx)?;+ let indent_guides = self.editor.update(cx, |editor, cx| {+ editor.indent_guides(visible_buffer_range, snapshot, cx)+ })?;let active_indent_guide_indices = self.editor.update(cx, |editor, cx| {editordiff --git a/crates/editor/src/indent_guides.rs b/crates/editor/src/indent_guides.rsindex 453f5f3b8f4..eb63050f709 100644--- a/crates/editor/src/indent_guides.rs+++ b/crates/editor/src/indent_guides.rs@@ -35,14 +35,11 @@ impl Editor {&self,visible_buffer_range: Range<MultiBufferRow>,snapshot: &DisplaySnapshot,- cx: &AppContext,+ cx: &mut ViewContext<Editor>,) -> Option<Vec<MultiBufferIndentGuide>> {- if self.show_indent_guides == Some(false) {- return None;- }+ let enabled = self.should_show_indent_guides(cx);- let settings = self.buffer.read(cx).settings_at(0, cx);- if settings.indent_guides.enabled {+ if enabled {Some(indent_guides_in_range(visible_buffer_range, snapshot, cx))} else {None