From 1cbf5525540531f26cd6bd765de93b20d96078f5 Mon Sep 17 00:00:00 2001 From: Saber Haj Rabiee Date: Wed, 31 Aug 2022 18:29:15 -0700 Subject: fix: prevents storing last prompt if is top of stack (#3609) --- helix-term/src/commands.rs | 2 +- helix-term/src/ui/prompt.rs | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) (limited to 'helix-term') diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 41960d35..cd92c42d 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1977,7 +1977,7 @@ fn extend_line_impl(cx: &mut Context, extend: Extend) { let end = text.line_to_char( match extend { Extend::Above => end_line + 1, // the start of next line - Extend::Below => (end_line + count), + Extend::Below => end_line + count, } .min(text.len_lines()), ); diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs index 1b2c35e9..24fc8233 100644 --- a/helix-term/src/ui/prompt.rs +++ b/helix-term/src/ui/prompt.rs @@ -533,18 +533,24 @@ impl Component for Prompt { if self.selection.is_some() && self.line.ends_with(std::path::MAIN_SEPARATOR) { self.recalculate_completion(cx.editor); } else { + let last_item = self + .history_register + .and_then(|reg| cx.editor.registers.last(reg).cloned()) + .map(|entry| entry.into()) + .unwrap_or_else(|| Cow::from("")); + // handle executing with last command in history if nothing entered let input: Cow = if self.line.is_empty() { - // latest value in the register list - self.history_register - .and_then(|reg| cx.editor.registers.last(reg).cloned()) - .map(|entry| entry.into()) - .unwrap_or_else(|| Cow::from("")) + last_item } else { - if let Some(register) = self.history_register { + if last_item != self.line { // store in history - let register = cx.editor.registers.get_mut(register); - register.push(self.line.clone()); + if let Some(register) = self.history_register { + cx.editor + .registers + .get_mut(register) + .push(self.line.clone()); + }; } self.line.as_str().into() -- cgit v1.2.3-70-g09d2