From 3b7760dfb0cdb547ff8c94f7685554f59d16bf0a Mon Sep 17 00:00:00 2001 From: ath3 Date: Tue, 15 Nov 2022 15:14:18 +0100 Subject: Refactor blackhole register (#4504) --- helix-term/src/ui/prompt.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'helix-term/src/ui') diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs index 51ef688d..b19b9a9f 100644 --- a/helix-term/src/ui/prompt.rs +++ b/helix-term/src/ui/prompt.rs @@ -294,23 +294,22 @@ impl Prompt { direction: CompletionDirection, ) { (self.callback_fn)(cx, &self.line, PromptEvent::Abort); - let register = cx.editor.registers.get_mut(register).read(); - - if register.is_empty() { - return; - } + let values = match cx.editor.registers.read(register) { + Some(values) if !values.is_empty() => values, + _ => return, + }; - let end = register.len().saturating_sub(1); + let end = values.len().saturating_sub(1); let index = match direction { CompletionDirection::Forward => self.history_pos.map_or(0, |i| i + 1), CompletionDirection::Backward => { - self.history_pos.unwrap_or(register.len()).saturating_sub(1) + self.history_pos.unwrap_or(values.len()).saturating_sub(1) } } .min(end); - self.line = register[index].clone(); + self.line = values[index].clone(); self.history_pos = Some(index); @@ -548,10 +547,7 @@ impl Component for Prompt { if last_item != self.line { // store in history if let Some(register) = self.history_register { - cx.editor - .registers - .get_mut(register) - .push(self.line.clone()); + cx.editor.registers.push(register, self.line.clone()); }; } -- cgit v1.2.3-70-g09d2