Skip to content

Commit

Permalink
fix: prevents storing last prompt if is top of stack (#3609)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabify authored Sep 1, 2022
1 parent ee94031 commit 1cbf552
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
);
Expand Down
22 changes: 14 additions & 8 deletions helix-term/src/ui/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<str> = 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()
Expand Down

0 comments on commit 1cbf552

Please sign in to comment.