Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Editor: Add shortcut to toggle line numbers (#8642)

Spence34de33ef72b2
diff --git a/assets/keymaps/default-linux.json b/assets/keymaps/default-linux.json
index 8f78a5dd090..5f6900713ab 100644
--- a/assets/keymaps/default-linux.json
+++ b/assets/keymaps/default-linux.json
@@ -117,7 +117,8 @@
{
"stop_at_soft_wraps": true
}
- ]
+ ],
+ "ctrl-;": "editor::ToggleLineNumbers"
}
},
{
diff --git a/assets/keymaps/default-macos.json b/assets/keymaps/default-macos.json
index 5872a2566b8..f5cc4f06a98 100644
--- a/assets/keymaps/default-macos.json
+++ b/assets/keymaps/default-macos.json
@@ -152,7 +152,8 @@
"center_cursor": true
}
],
- "ctrl-cmd-space": "editor::ShowCharacterPalette"
+ "ctrl-cmd-space": "editor::ShowCharacterPalette",
+ "cmd-;": "editor::ToggleLineNumbers"
}
},
{
diff --git a/crates/editor/src/actions.rs b/crates/editor/src/actions.rs
index fb4e3fbddcf..ae7cd99c075 100644
--- a/crates/editor/src/actions.rs
+++ b/crates/editor/src/actions.rs
@@ -239,6 +239,7 @@ gpui::actions!(
TabPrev,
ToggleInlayHints,
ToggleSoftWrap,
+ ToggleLineNumbers,
Transpose,
Undo,
UndoSelection,
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs
index b3adf64a943..e92f116837c 100644
--- a/crates/editor/src/editor.rs
+++ b/crates/editor/src/editor.rs
@@ -8586,6 +8586,12 @@ impl Editor {
cx.notify();
}
+ 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;
+ EditorSettings::override_global(editor_settings, cx);
+ }
+
pub fn set_show_gutter(&mut self, show_gutter: bool, cx: &mut ViewContext<Self>) {
self.show_gutter = show_gutter;
cx.notify();
diff --git a/crates/editor/src/editor_settings.rs b/crates/editor/src/editor_settings.rs
index cff68e689ea..ca12112d5f5 100644
--- a/crates/editor/src/editor_settings.rs
+++ b/crates/editor/src/editor_settings.rs
@@ -2,7 +2,7 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use settings::Settings;
-#[derive(Deserialize)]
+#[derive(Deserialize, Clone)]
pub struct EditorSettings {
pub cursor_blink: bool,
pub hover_popover_enabled: bool,
diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs
index 0f3ee3ec62c..0082ff343c4 100644
--- a/crates/editor/src/element.rs
+++ b/crates/editor/src/element.rs
@@ -275,6 +275,7 @@ impl EditorElement {
register_action(view, cx, Editor::open_excerpts);
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_inlay_hints);
register_action(view, cx, hover_popover::hover);
register_action(view, cx, Editor::reveal_in_finder);