Skip to content

Commit

Permalink
fix: If backspacing past the start offset, cancel completion
Browse files Browse the repository at this point in the history
Refs #822
  • Loading branch information
archseer committed Oct 16, 2021
1 parent be428a2 commit 2c0468f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions helix-term/src/ui/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ impl Completion {
let text = Cow::from(fragment);
// TODO: logic is same as ui/picker
menu.score(&text);
} else {
// we backspaced before the start offset, clear the menu
// this will cause the editor to remove the completion popup
menu.clear();
}
}

Expand Down
8 changes: 8 additions & 0 deletions helix-term/src/ui/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ impl<T: Item> Menu<T> {
self.recalculate = true;
}

pub fn clear(&mut self) {
self.matches.clear();

// reset cursor position
self.cursor = None;
self.scroll = 0;
}

pub fn move_up(&mut self) {
let len = self.matches.len();
let pos = self.cursor.map_or(0, |i| (i + len.saturating_sub(1)) % len) % len;
Expand Down

0 comments on commit 2c0468f

Please sign in to comment.