fix: If backspacing past the start offset, cancel completion

Refs #822
This commit is contained in:
Blaž Hrastnik 2021-10-16 18:43:07 +09:00
parent be428a295a
commit 2c0468ffd1
2 changed files with 12 additions and 0 deletions

View file

@ -215,6 +215,10 @@ pub fn recompute_filter(&mut self, editor: &Editor) {
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();
}
}

View file

@ -90,6 +90,14 @@ pub fn score(&mut self, pattern: &str) {
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;