From 70ebaa88978a434c51d1ccb516584c148e41c4f1 Mon Sep 17 00:00:00 2001 From: Ellis Gibbons Date: Sat, 3 Jun 2023 15:43:28 -0400 Subject: [PATCH] Add visual feedback for select_register command Resolves issue #1585 by adding a status message when a register is selected, similar to the message produced when recording a macro. Additionally, an indicator appears on the right. --- helix-term/src/commands.rs | 1 + helix-term/src/ui/editor.rs | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 911c9c1f7e401..9de57dbe316eb 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -4701,6 +4701,7 @@ fn select_register(cx: &mut Context) { if let Some(ch) = event.char() { cx.editor.autoinfo = None; cx.editor.selected_register = Some(ch); + cx.editor.set_status(format!("Selected register [{}]", ch)); } }) } diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 43b5d1af6ec3f..bbcdc65e09b4f 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -1447,13 +1447,18 @@ impl Component for EditorView { disp.push_str(&key.key_sequence_format()); } let style = cx.editor.theme.get("ui.text"); - let macro_width = if cx.editor.macro_recording.is_some() { + + let macro_active = cx.editor.macro_recording.is_some(); + let register_active = cx.editor.selected_register.is_some(); + let macro_reg_width = if macro_active && register_active { + 7 + } else if macro_active ^ register_active { 3 } else { 0 }; surface.set_string( - area.x + area.width.saturating_sub(key_width + macro_width), + area.x + area.width.saturating_sub(key_width + macro_reg_width), area.y + area.height.saturating_sub(1), disp.get(disp.len().saturating_sub(key_width as usize)..) .unwrap_or(&disp), @@ -1471,6 +1476,18 @@ impl Component for EditorView { style, ); } + if let Some(reg) = cx.editor.selected_register { + let disp = format!("[{}]", reg); + let style = style + .fg(helix_view::graphics::Color::Cyan) + .add_modifier(Modifier::BOLD); + surface.set_string( + area.x + area.width.saturating_sub(macro_reg_width), + area.y + area.height.saturating_sub(1), + &disp, + style, + ); + } } if let Some(completion) = self.completion.as_mut() {