on master help sign in
fix: prevents storing last prompt if is top of stack (#3609)
1cbf552Saber Haj Rabiee
helix-term/src/commands.rs+1−1
@@ -1977,7 +1977,7 @@ fn extend_line_impl(cx: &mut Context, extend: Extend) {
1977 let end = text.line_to_char(
1977 let end = text.line_to_char(
1978 match extend {
1978 match extend {
1979 Extend::Above => end_line + 1, // the start of next line
1979 Extend::Above => end_line + 1, // the start of next line
1980− Extend::Below => (end_line + count),
1980+ Extend::Below => end_line + count,
1981 }
1981 }
1982 .min(text.len_lines()),
1982 .min(text.len_lines()),
1983 );
1983 );
helix-term/src/ui/prompt.rs+14−8
@@ -533,18 +533,24 @@ impl Component for Prompt {
533 if self.selection.is_some() && self.line.ends_with(std::path::MAIN_SEPARATOR) {
533 if self.selection.is_some() && self.line.ends_with(std::path::MAIN_SEPARATOR) {
534 self.recalculate_completion(cx.editor);
534 self.recalculate_completion(cx.editor);
535 } else {
535 } 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+
536 // handle executing with last command in history if nothing entered
542 // handle executing with last command in history if nothing entered
537 let input: Cow<str> = if self.line.is_empty() {
543 let input: Cow<str> = if self.line.is_empty() {
538− // latest value in the register list
544+ last_item
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(""))
543 } else {
545 } else {
544− if let Some(register) = self.history_register {
546+ if last_item != self.line {
545 // store in history
547 // store in history
548+ if let Some(register) = self.history_register {
549+ cx.editor
550+ .registers
546− let register = cx.editor.registers.get_mut(register);
551+ .get_mut(register)
547− register.push(self.line.clone());
552+ .push(self.line.clone());
553+ };
548 }
554 }
549
555
550 self.line.as_str().into()
556 self.line.as_str().into()