on master help sign in
Implement black hole register (#1165)
commit1d773bcefb40f69fe31dc048bfbdd83601fe0e62 authorath3 <45574139+ath3@users.noreply.github.com> dateSun 28 Nov 2021, 02:21 (5 years ago) parent103b512
2 files changed+13−3
book/src/usage.md+2 helix-core/src/register.rs+11−3
book/src/usage.md+2
@@ -23,8 +23,10 @@ If there is a selected register before invoking a change or delete command, the
2323| `/` | Last search |
2424| `:` | Last executed command |
2525| `"` | Last yanked text |
26+| `_` | Black hole |
2627
2728> 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.
29+> The black hole register works as a no-op register, meaning no data will be written to / read from it.
2830
2931## Surround
3032
helix-core/src/register.rs+11−3
@@ -15,7 +15,11 @@ impl Register {
1515 }
1616
1717 pub fn new_with_values(name: char, values: Vec<String>) -> Self {
18− Self { name, values }
18+ if name == '_' {
19+ Self::new(name)
20+ } else {
21+ Self { name, values }
22+ }
1923 }
2024
2125 pub const fn name(&self) -> char {
@@ -27,11 +31,15 @@ impl Register {
2731 }
2832
2933 pub fn write(&mut self, values: Vec<String>) {
30− self.values = values;
34+ if self.name != '_' {
35+ self.values = values;
36+ }
3137 }
3238
3339 pub fn push(&mut self, value: String) {
34− self.values.push(value);
40+ if self.name != '_' {
41+ self.values.push(value);
42+ }
3543 }
3644}
3745