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

Strange off-by-one error when hitting <Tab> in the command line #187

Open
wookayin opened this issue Apr 28, 2023 · 3 comments
Open

Strange off-by-one error when hitting <Tab> in the command line #187

wookayin opened this issue Apr 28, 2023 · 3 comments

Comments

@wookayin
Copy link

On neovim 0.9.0 or higher, hitting to insert and accept the completion suggestion would result in an off-by-one error:

For example, if the first completion item for :lua vim.api.<Tab> is nvim__buf_redraw_range, then hitting <Tab> inserts

:lua vim.api.nnvim__buf_redraw_range
             ^
             |
       extra wrong character!

Also the fuzzy matching is also mis-aligned by offset 1:

image

The key mapping I use for <Tab> is

  cmap <expr> <Tab>   wilder#in_context() ? wilder#next()     : "\<Tab>"

which is simply wilder#next() in this context.

@wookayin
Copy link
Author

https://github.com/gelguy/wilder.nvim/blob/master/autoload/wilder/main.vim#L603-L632

Scenario: lua vim.ap<TAB>

s:result has:

(nvim 0.8.3, correct)

data = {
  "cmdline.match_arg": "ap",
  "query": "ap",
  "cmdline.lua_prefix": "vim."
}

(nvim 0.9.0, incorrect)

data = {
  "cmdline.match_arg": "p",
  "query": "p",
  "cmdline.lua_prefix": "vim.a"
}

In s:get_lua_completion, a helper function vim._expand_pat is used but its implementation seems to have changed.

vim._expand_pat("^vim.ap") gives:

  • 0.9.x: {"api"}, 5
  • 0.8.x: {"api"}, 4

But why?

wookayin added a commit to wookayin/wilder.nvim that referenced this issue Apr 28, 2023
A private method vim._expand_pat (which should not be used) has
changed the behavior, which causes an off-by-one error in completion.

As a temporary workaround, we manually offset the match position.
@ShangjinTang
Copy link

ShangjinTang commented Jul 22, 2023

I also get the same strange off-by-one error as above.

This commit wookayin@9929e10 can fix the issue, but it has a side-effect that the first key word will always show "No candidates found".

@vds2212
Copy link

vds2212 commented Oct 19, 2023

I notice the same behavior with Neovim 0.9.3 and Windows 10.

cuducos added a commit to cuducos/dotfiles that referenced this issue Aug 6, 2024
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

No branches or pull requests

3 participants