on master help sign in
Implement black hole register (#1165)
1d773bcath3
book/src/usage.md+2
@@ -23,8 +23,10 @@ If there is a selected register before invoking a change or delete command, the
23| `/` | Last search |
23| `/` | Last search |
24| `:` | Last executed command |
24| `:` | Last executed command |
25| `"` | Last yanked text |
25| `"` | Last yanked text |
26+| `_` | Black hole |
26
27
27> 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.
28> 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.
28
30
29## Surround
31## Surround
30
32
helix-core/src/register.rs+11−3
@@ -15,7 +15,11 @@ impl Register {
15 }
15 }
16
16
17 pub fn new_with_values(name: char, values: Vec<String>) -> Self {
17 pub fn new_with_values(name: char, values: Vec<String>) -> Self {
18+ if name == '_' {
19+ Self::new(name)
20+ } else {
18− Self { name, values }
21+ Self { name, values }
22+ }
19 }
23 }
20
24
21 pub const fn name(&self) -> char {
25 pub const fn name(&self) -> char {
@@ -27,11 +31,15 @@ impl Register {
27 }
31 }
28
32
29 pub fn write(&mut self, values: Vec<String>) {
33 pub fn write(&mut self, values: Vec<String>) {
34+ if self.name != '_' {
30− self.values = values;
35+ self.values = values;
36+ }
31 }
37 }
32
38
33 pub fn push(&mut self, value: String) {
39 pub fn push(&mut self, value: String) {
40+ if self.name != '_' {
34− self.values.push(value);
41+ self.values.push(value);
42+ }
35 }
43 }
36}
44}
37
45