on master help sign in
Clear completion when switching windows via click (#8118)

The completion component assumes that it operates on the same View but it's possible to break this assumption by switching windows through left-clicking. I believe we should clear the completion menu when switching windows to fix this. This change fixes a panic for this scenario: * Open a buffer with LSP completion available * Split the window (for example '<C-w>v') * Enter insert mode and trigger the completion menu * Select a completion candidate (for example with '<C-n>') * Switch to the original window by left-clicking in its area * Enter insert mode and make edits (for example 'o<backspace>') This will trip the 'assert_eq' in Document::restore.

commit48373d4a2b6402dce91ebcdf29b6341fcf0ba302 authorMichael Davis <mcarsondavis@gmail.com> dateThu 31 Aug 2023, 01:12 (3 years ago) parenta276726
1 file changed+5
helix-term/src/ui/editor.rs+5
helix-term/src/ui/editor.rs+5
@@ -1073,6 +1073,7 @@ impl EditorView {
10731073 let editor = &mut cxt.editor;
10741074
10751075 if let Some((pos, view_id)) = pos_and_view(editor, row, column, true) {
1076+ let prev_view_id = view!(editor).id;
10761077 let doc = doc_mut!(editor, &view!(editor, view_id).doc);
10771078
10781079 if modifiers == KeyModifiers::ALT {
@@ -1082,6 +1083,10 @@ impl EditorView {
10821083 doc.set_selection(view_id, Selection::point(pos));
10831084 }
10841085
1086+ if view_id != prev_view_id {
1087+ self.clear_completion(editor);
1088+ }
1089+
10851090 editor.focus(view_id);
10861091 editor.ensure_cursor_in_view(view_id);
10871092