From ee05cc3ad984559f0cf8a24eb1b9967a00af5164 Mon Sep 17 00:00:00 2001 From: Danilo Leal <67129314+danilo-leal@users.noreply.github.com> Date: Mon, 10 Mar 2025 09:28:46 -0300 Subject: [PATCH] Add a line numbers toggle to the editor controls menu (#26318) Closes https://github.com/zed-industries/zed/issues/26305 Release Notes: - N/A --- crates/editor/src/editor.rs | 7 +++ crates/zed/src/zed/quick_action_bar.rs | 82 +++++++++++++++++--------- 2 files changed, 60 insertions(+), 29 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index b937bac242..0ce23d77dd 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.rs index 4da1a13148..974a210dd4 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(