Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear completion when switching windows via click #8118

Conversation

the-mikedavis
Copy link
Member

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.

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.
@the-mikedavis the-mikedavis added C-bug Category: This is a bug S-waiting-on-review Status: Awaiting review from a maintainer. labels Aug 30, 2023
@the-mikedavis
Copy link
Member Author

Ideally we would close completion on any window switch from within Editor::focus but I believe that would need the move-compositor-to-helix-view change (#5632 (comment))

Copy link
Member

@pascalkuthe pascalkuthe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can merge this as is to get the panic out of tree but I actually included the same fix in #8021 :D

Sorry I confused something. This is a good catch! Not quite as good as doing it in editor::focus but realistically changing focus while a prompt is otherwise impossible anyway.

@pascalkuthe
Copy link
Member

Ideally we would close completion on any window switch from within Editor::focus but I believe that would need the move-compositor-to-helix-view change (#5632 (comment))

That issue was about the search prompt not completion. Could we do the same there (close the current prompt)?

@the-mikedavis
Copy link
Member Author

Yeah, I just mean that for both prompts and completion that we need access to the compositor from within (helix-view's) Editor to solve it really nicely as you say in #5632.

It should be possible to also close other components here:

let callback = if view_id != prev_view_id {
    self.clear_completion(editor);
    let callback: crate::compositor::Callback = Box::new(|compositor, _| {
        // Close any prompts or other components.
    });
    Some(callback)
} else {
    None
};

editor.focus(view_id);
editor.ensure_cursor_in_view(view_id);

return EventResult::Consumed(callback);

But that may need larger changes to the prompt and maybe other components. We would want to cancel whatever the prompt had selected, for example if you had :theme <sometheme> previewed and clicked another pane then it would essentially accept the preview but I would expect the prompt to cancel (PromptEvent::Abort).

I think it's possible with some more changes to the components that could be closed but it isn't quite trivial so I'd like to leave it off of this PR if possible.

@archseer archseer merged commit 48373d4 into helix-editor:master Aug 31, 2023
6 checks passed
@the-mikedavis the-mikedavis deleted the md-clear-completion-when-switching-windows-via-click branch August 31, 2023 16:11
acristoffers pushed a commit to acristoffers/helix that referenced this pull request Nov 18, 2023
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.
dgkf pushed a commit to dgkf/helix that referenced this pull request Jan 30, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants