Skip to content

Commit

Permalink
Implement black hole register (helix-editor#1165)
Browse files Browse the repository at this point in the history
  • Loading branch information
ath3 authored Nov 28, 2021
1 parent 103b512 commit 1d773bc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions book/src/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ If there is a selected register before invoking a change or delete command, the
| `/` | Last search |
| `:` | Last executed command |
| `"` | Last yanked text |
| `_` | Black hole |

> There is no special register for copying to system clipboard, instead special commands and keybindings are provided. See the [keymap](keymap.md#space-mode) for the specifics.
> The black hole register works as a no-op register, meaning no data will be written to / read from it.
## Surround

Expand Down
14 changes: 11 additions & 3 deletions helix-core/src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ impl Register {
}

pub fn new_with_values(name: char, values: Vec<String>) -> Self {
Self { name, values }
if name == '_' {
Self::new(name)
} else {
Self { name, values }
}
}

pub const fn name(&self) -> char {
Expand All @@ -27,11 +31,15 @@ impl Register {
}

pub fn write(&mut self, values: Vec<String>) {
self.values = values;
if self.name != '_' {
self.values = values;
}
}

pub fn push(&mut self, value: String) {
self.values.push(value);
if self.name != '_' {
self.values.push(value);
}
}
}

Expand Down

0 comments on commit 1d773bc

Please sign in to comment.