on master help sign in
fix: If backspacing past the start offset, cancel completion

Refs #822

commit2c0468ffd16de1f835ac9c4e39692a682273fb7b authorBlaž Hrastnik <blaz@mxxn.io> dateSat 16 Oct 2021, 18:43 (5 years ago) parentbe428a2
2 files changed+12
helix-term/src/ui/completion.rs+4 helix-term/src/ui/menu.rs+8
helix-term/src/ui/completion.rs+4
@@ -215,6 +215,10 @@ impl Completion {
215215 let text = Cow::from(fragment);
216216 // TODO: logic is same as ui/picker
217217 menu.score(&text);
218+ } else {
219+ // we backspaced before the start offset, clear the menu
220+ // this will cause the editor to remove the completion popup
221+ menu.clear();
218222 }
219223 }
220224
helix-term/src/ui/menu.rs+8
@@ -90,6 +90,14 @@ impl<T: Item> Menu<T> {
9090 self.recalculate = true;
9191 }
9292
93+ pub fn clear(&mut self) {
94+ self.matches.clear();
95+
96+ // reset cursor position
97+ self.cursor = None;
98+ self.scroll = 0;
99+ }
100+
93101 pub fn move_up(&mut self) {
94102 let len = self.matches.len();
95103 let pos = self.cursor.map_or(0, |i| (i + len.saturating_sub(1)) % len) % len;