on master help sign in
fix: prevents storing last prompt if is top of stack (#3609)
commit1cbf5525540531f26cd6bd765de93b20d96078f5 authorSaber Haj Rabiee <sabify@users.noreply.github.com> dateWed 31 Aug 2022, 18:29 (4 years ago) parentee94031
2 files changed+15−9
helix-term/src/commands.rs+1−1 helix-term/src/ui/prompt.rs+14−8
helix-term/src/commands.rs+1−1
@@ -1977,7 +1977,7 @@ fn extend_line_impl(cx: &mut Context, extend: Extend) {
19771977 let end = text.line_to_char(
19781978 match extend {
19791979 Extend::Above => end_line + 1, // the start of next line
1980− Extend::Below => (end_line + count),
1980+ Extend::Below => end_line + count,
19811981 }
19821982 .min(text.len_lines()),
19831983 );
helix-term/src/ui/prompt.rs+14−8
@@ -533,18 +533,24 @@ impl Component for Prompt {
533533 if self.selection.is_some() && self.line.ends_with(std::path::MAIN_SEPARATOR) {
534534 self.recalculate_completion(cx.editor);
535535 } else {
536+ let last_item = self
537+ .history_register
538+ .and_then(|reg| cx.editor.registers.last(reg).cloned())
539+ .map(|entry| entry.into())
540+ .unwrap_or_else(|| Cow::from(""));
541+
536542 // handle executing with last command in history if nothing entered
537543 let input: Cow<str> = if self.line.is_empty() {
538− // latest value in the register list
539− self.history_register
540− .and_then(|reg| cx.editor.registers.last(reg).cloned())
541− .map(|entry| entry.into())
542− .unwrap_or_else(|| Cow::from(""))
544+ last_item
543545 } else {
544− if let Some(register) = self.history_register {
546+ if last_item != self.line {
545547 // store in history
546− let register = cx.editor.registers.get_mut(register);
547− register.push(self.line.clone());
548+ if let Some(register) = self.history_register {
549+ cx.editor
550+ .registers
551+ .get_mut(register)
552+ .push(self.line.clone());
553+ };
548554 }
549555
550556 self.line.as_str().into()