on master help sign in
fix: If backspacing past the start offset, cancel completion
2c0468fBlaž Hrastnik
helix-term/src/ui/completion.rs+4
@@ -215,6 +215,10 @@ impl Completion {
215 let text = Cow::from(fragment);
215 let text = Cow::from(fragment);
216 // TODO: logic is same as ui/picker
216 // TODO: logic is same as ui/picker
217 menu.score(&text);
217 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();
218 }
222 }
219 }
223 }
220
224
helix-term/src/ui/menu.rs+8
@@ -90,6 +90,14 @@ impl<T: Item> Menu<T> {
90 self.recalculate = true;
90 self.recalculate = true;
91 }
91 }
92
92
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+
93 pub fn move_up(&mut self) {
101 pub fn move_up(&mut self) {
94 let len = self.matches.len();
102 let len = self.matches.len();
95 let pos = self.cursor.map_or(0, |i| (i + len.saturating_sub(1)) % len) % len;
103 let pos = self.cursor.map_or(0, |i| (i + len.saturating_sub(1)) % len) % len;