diff options
Diffstat (limited to 'helix-term/src/ui/prompt.rs')
-rw-r--r-- | helix-term/src/ui/prompt.rs | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs index a5be33ff..64154bae 100644 --- a/helix-term/src/ui/prompt.rs +++ b/helix-term/src/ui/prompt.rs @@ -442,10 +442,21 @@ impl Prompt { let line = area.height - 1; // render buffer text surface.set_string(area.x, area.y + line, &self.prompt, prompt_color); + + let input: Cow<str> = if self.line.is_empty() { + // latest value in the register list + self.history_register + .and_then(|reg| cx.editor.registers.first(reg).cloned()) // TODO: can we avoid cloning? + .map(|entry| entry.into()) + .unwrap_or_else(|| Cow::from("")) + } else { + self.line.as_str().into() + }; + surface.set_string( area.x + self.prompt.len() as u16, area.y + line, - &self.line, + &input, prompt_color, ); } @@ -510,7 +521,18 @@ impl Component for Prompt { self.recalculate_completion(cx.editor); self.exit_selection(); } else { - (self.callback_fn)(cx, &self.line, PromptEvent::Validate); + // handle executing with last command in history if nothing entered + let input: Cow<str> = if self.line.is_empty() { + // latest value in the register list + self.history_register + .and_then(|reg| cx.editor.registers.first(reg).cloned()) + .map(|entry| entry.into()) + .unwrap_or_else(|| Cow::from("")) + } else { + self.line.as_str().into() + }; + + (self.callback_fn)(cx, &input, PromptEvent::Validate); if let Some(register) = self.history_register { // store in history |