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

remove Enter keybinding from menu picker #1622

Conversation

the-mikedavis
Copy link
Member

@the-mikedavis the-mikedavis commented Feb 6, 2022

I've been running with this commit in my build for a bit, it fixes a wonky scenario where I want Enter to create a newline but instead it only closes the completion menu. It happens very often in Elixir because of do/end blocks:

defmodule MyModule do
  def do_foo(x) do
    x
  end
  def other_function(y) do|
end

(Where I'm in insert mode after typing that 'do' next to the cursor '|'). The LSP will bring up the menu to suggest do_foo/1, so when I hit Enter to start a new line, the completion menu is closed but the newline isn't inserted.

I think this change also makes sense because

  • Ctrl+n/p/j/k change the current token to the suggestion, so there's never a need to "confirm" a suggestion
  • Ctrl+c or Esc currently have the same behavior as Enter (although this might be a bug, I suspect Ctrl+c and Esc are supposed to restore the text to what it was before any Ctrl+n/p/j/k changes?)

@archseer
Copy link
Member

archseer commented Feb 6, 2022

I'm assuming you have completion delay set to 0? If I remember correctly, we can now both ignore the event and trigger a callback so what I'd do is: if an option is selected, trigger it and close the menu, or if no option is selected, close the menu and trigger a newline.

@archseer
Copy link
Member

archseer commented Feb 6, 2022

Might need changes from #1285 though, which adds that "ignore + callback" return

@sudormrfbin
Copy link
Member

How will this interact with additional text changes like auto-imports ? IIRC it's triggered on Enter.

@archseer
Copy link
Member

archseer commented Feb 6, 2022

I need to double check but I think I addressed that with the "snapshot" feature and it's now always applied and reverted

@the-mikedavis
Copy link
Member Author

I'm assuming you have completion delay set to 0?

Yep, I forgot about that setting, I should probably try with something very small, I bet that'd fix it most of the time.

And #1285 and EventResult::Ignored look perfect for this. I'll close this PR out for now and give a real fix a try once #1285 is in.

@the-mikedavis the-mikedavis deleted the md-remove-enter-from-menu branch February 6, 2022 17:43
the-mikedavis added a commit to the-mikedavis/helix that referenced this pull request Feb 23, 2022
supersedes helix-editor#1622

Builds on the work in helix-editor#1285. I want to allow Enter to create a newline
when there is no selection in the autocomplete menu.

This occurs somewhat often when using LSP autocomplete in Elixir which
uses `do/end` blocks (and I set the autocomplete menu delay to 0 which
exacerbates the problem):

```elixir
defmodule MyModule do
  def do_foo(x) do
    x
  end
  def other_function(y) do|
end
```

Here the cursor is `|` in insert mode. The LSP suggests `do_foo` but I
want to create a newline. Hitting Enter currently closes the menu,
so I end up having to hit Enter twice when the module contains any
local with a `do` prefix, which can be inconsistent. With this change,
we ignore the Enter keypress to end up creating the newline in this case.
archseer pushed a commit that referenced this pull request Feb 27, 2022
* ignore Enter keypress when menu has no selection

supersedes #1622

Builds on the work in #1285. I want to allow Enter to create a newline
when there is no selection in the autocomplete menu.

This occurs somewhat often when using LSP autocomplete in Elixir which
uses `do/end` blocks (and I set the autocomplete menu delay to 0 which
exacerbates the problem):

```elixir
defmodule MyModule do
  def do_foo(x) do
    x
  end
  def other_function(y) do|
end
```

Here the cursor is `|` in insert mode. The LSP suggests `do_foo` but I
want to create a newline. Hitting Enter currently closes the menu,
so I end up having to hit Enter twice when the module contains any
local with a `do` prefix, which can be inconsistent. With this change,
we ignore the Enter keypress to end up creating the newline in this case.

* pop compositor layer when ignoring Enter keypress

* move closing function out of consumed event result closure

* explicitly label close_fn as an 'Option<Callback>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants