Skip to content

Commit

Permalink
Add visual feedback for select_register command
Browse files Browse the repository at this point in the history
Resolves issue helix-editor#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.
  • Loading branch information
spectre256 committed Jun 3, 2023
1 parent d511122 commit 70ebaa8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
})
}
Expand Down
21 changes: 19 additions & 2 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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() {
Expand Down

0 comments on commit 70ebaa8

Please sign in to comment.