Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Add a line numbers toggle to the editor controls menu (#26318)
Danilo Lealee05cc3ad984
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex b937bac2425..0ce23d77ddf 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -14303,6 +14303,13 @@ impl Editor {EditorSettings::override_global(editor_settings, cx);}+ pub fn line_numbers_enabled(&self, cx: &App) -> bool {+ if let Some(show_line_numbers) = self.show_line_numbers {+ return show_line_numbers;+ }+ EditorSettings::get_global(cx).gutter.line_numbers+ }+pub fn should_use_relative_line_numbers(&self, cx: &mut App) -> bool {self.use_relative_line_numbers.unwrap_or(EditorSettings::get_global(cx).relative_line_numbers)diff --git a/crates/zed/src/zed/quick_action_bar.rs b/crates/zed/src/zed/quick_action_bar.rsindex 4da1a13148b..974a210dd46 100644--- a/crates/zed/src/zed/quick_action_bar.rs+++ b/crates/zed/src/zed/quick_action_bar.rs@@ -96,6 +96,7 @@ impl Render for QuickActionBar {let git_blame_inline_enabled = editor_value.git_blame_inline_enabled();let show_git_blame_gutter = editor_value.show_git_blame_gutter();let auto_signature_help_enabled = editor_value.auto_signature_help_enabled(cx);+ let show_line_numbers = editor_value.line_numbers_enabled(cx);let has_edit_prediction_provider = editor_value.edit_prediction_provider().is_some();let show_edit_predictions = editor_value.edit_predictions_enabled();let edit_predictions_enabled_at_cursor =@@ -261,6 +262,58 @@ impl Render for QuickActionBar {);}+ 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)+ .disabled(!edit_predictions_enabled_at_cursor)+ .action(+ editor::actions::ToggleEditPrediction.boxed_clone(),+ ).handler({+ let editor = editor.clone();+ move |window, cx| {+ editor+ .update(cx, |editor, cx| {+ editor.toggle_edit_predictions(+ &editor::actions::ToggleEditPrediction,+ window,+ cx,+ );+ })+ .ok();+ }+ });+ if !edit_predictions_enabled_at_cursor {+ inline_completion_entry = inline_completion_entry.documentation_aside(|_| {+ Label::new("You can't toggle edit predictions for this file as it is within the excluded files list.").into_any_element()+ });+ }++ menu = menu.item(inline_completion_entry);+ }++ menu = menu.separator();++ menu = menu.toggleable_entry(+ "Line Numbers",+ show_line_numbers,+ IconPosition::Start,+ Some(editor::actions::ToggleLineNumbers.boxed_clone()),+ {+ let editor = editor.clone();+ move |window, cx| {+ editor+ .update(cx, |editor, cx| {+ editor.toggle_line_numbers(+ &editor::actions::ToggleLineNumbers,+ window,+ cx,+ );+ })+ .ok();+ }+ },+ );+menu = menu.toggleable_entry("Selection Menu",selection_menu_enabled,@@ -303,35 +356,6 @@ impl Render for QuickActionBar {},);- 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)- .disabled(!edit_predictions_enabled_at_cursor)- .action(- editor::actions::ToggleEditPrediction.boxed_clone(),- ).handler({- let editor = editor.clone();- move |window, cx| {- editor- .update(cx, |editor, cx| {- editor.toggle_edit_predictions(- &editor::actions::ToggleEditPrediction,- window,- cx,- );- })- .ok();- }- });- if !edit_predictions_enabled_at_cursor {- inline_completion_entry = inline_completion_entry.documentation_aside(|_| {- Label::new("You can't toggle edit predictions for this file as it is within the excluded files list.").into_any_element()- });- }-- menu = menu.item(inline_completion_entry);- }-menu = menu.separator();menu = menu.toggleable_entry(