From 76277a416d464fb37aa3173e421caea2e283ed6f Mon Sep 17 00:00:00 2001 From: Jorge Date: Fri, 21 Oct 2022 17:22:23 +0200 Subject: [PATCH] feat(commands): add clear_registers command --- book/src/keymap.md | 1 + helix-core/src/register.rs | 4 ++++ helix-term/src/commands.rs | 7 +++++++ helix-term/src/keymap/default.rs | 1 + 4 files changed, 13 insertions(+) diff --git a/book/src/keymap.md b/book/src/keymap.md index 0550e57f3f3b5..c679a014046be 100644 --- a/book/src/keymap.md +++ b/book/src/keymap.md @@ -289,6 +289,7 @@ This layer is a kludge of mappings, mostly pickers. | `Y` | Yank main selection to clipboard | `yank_main_selection_to_clipboard` | | `R` | Replace selections by clipboard contents | `replace_selections_with_clipboard` | | `/` | Global search in workspace folder | `global_search` | +| `|` | Clear all registers | `clear_registers` | | `?` | Open command palette | `command_palette` | > TIP: Global search displays results in a fuzzy picker, use `Space + '` to bring it back up after opening a file. diff --git a/helix-core/src/register.rs b/helix-core/src/register.rs index 52eb6e3e72bf3..db814ccec0cff 100644 --- a/helix-core/src/register.rs +++ b/helix-core/src/register.rs @@ -78,4 +78,8 @@ impl Registers { pub fn inner(&self) -> &HashMap { &self.inner } + + pub fn clear(&mut self) { + self.inner.clear(); + } } diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 365d5b6594c2f..817c378792757 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -392,6 +392,7 @@ impl MappableCommand { wonly, "Close windows except current", select_register, "Select register", insert_register, "Insert register", + clear_registers, "Clear registers", align_view_middle, "Align view middle", align_view_top, "Align view top", align_view_center, "Align view center", @@ -4457,6 +4458,12 @@ fn insert_register(cx: &mut Context) { }) } +fn clear_registers(cx: &mut Context) { + cx.editor.autoinfo = None; + cx.editor.registers.clear(); + cx.editor.set_status("All registers cleared.") +} + fn align_view_top(cx: &mut Context) { let (view, doc) = current!(cx.editor); align_view(doc, view, Align::Top); diff --git a/helix-term/src/keymap/default.rs b/helix-term/src/keymap/default.rs index ef93dee08a777..f1a927afd4a1d 100644 --- a/helix-term/src/keymap/default.rs +++ b/helix-term/src/keymap/default.rs @@ -269,6 +269,7 @@ pub fn default() -> HashMap { "k" => hover, "r" => rename_symbol, "h" => select_references_to_symbol_under_cursor, + "|" => clear_registers, "?" => command_palette, }, "z" => { "View"