-
Notifications
You must be signed in to change notification settings - Fork 233
Added a preselect option to the cmp menu #24
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
Conversation
To fix #14. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! I'd prefer a boolean has_selected
that gets reset to config.windows.autocomplete.preselect
on new context.id
values. Would be great to have a set_has_selected
that handles showing/hiding cursorline as well, making sure to double check autocomplete.win:is_open()
Something I've noticed when testing: if we continue typing while the autocompletion window is opened, it stays open and the result just get filtered. My question is, when in "not preselect" mode, should the selection reset when the completions items get updated? In not preselect mode, If the user native through the items but decide to choose none, he doesn't expect the selection to jump back to first item as he continue typing. He would simply use Tab and S-Tab to select an item if he want to accept this new suggestion. Thus I think it's better to reset the selection ( has_selected = false ) when the list get updated. |
Yep, good point. I believe you'd want to check if the cursor position changes, rather than checking if the items have changed, since items can be updated twice per keystroke. On keystroke, the list gets immediately re-filtered with stale data. The sources are called and the list gets updated again asynchronously, if there's new data |
Hmm, I didn't run into this, so it'd be hard to check. As far as I know this shouldn't impact this PR much? the only modification are in the select_prev/next function. function autocomplete.select_prev()
if not autocomplete.win:is_open() then return end
local cycle_from_top = config.windows.autocomplete.cycle.from_top
local l = #autocomplete.items
local line = vim.api.nvim_win_get_cursor(autocomplete.win:get_win())[1]
if line <= 1 then
if not cycle_from_top then return end
line = l
else
line = line - 1
end
autocomplete.set_has_selected(true)
autocomplete.win:set_option_values('cursorline', true)
vim.api.nvim_win_set_cursor(autocomplete.win:get_win(), { line, 0 })
autocomplete.event_targets.on_select(autocomplete.get_selected_item(), autocomplete.context)
end Which get line info from the current cursor position. |
cycle = { | ||
from_bottom = true, | ||
from_top = true, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These configs are already documented as part of windows.autocomplete
:
Line 254 in 48f0316
cycle = { |
cycle = { | |
from_bottom = true, | |
from_top = true, | |
}, |
from_bottom = true, | ||
from_top = true, | ||
}, | ||
preselect = true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you meant to put this in the windows.autocomplete
section, as per:
blink.cmp/lua/blink/cmp/config.lua
Line 250 in 48f0316
preselect = true, |
You're right, I forgot to stage those, my bad |
Thanks again, I'll wrap up the remaining small changes on main |
* feat: Added a preselect option to the cmp menu * fix: implement requested changes * fix: silly not * fix: Completion select on the second line Squash me! * Add default config to the readme * Fix: duplicated field in default config
* feat: Added a preselect option to the cmp menu * fix: implement requested changes * fix: silly not * fix: Completion select on the second line Squash me! * Add default config to the readme * Fix: duplicated field in default config
I'm a bit confused here. Is this feature wrapped up? I cannot seem to get it to work. |
I'm on the latest version and, weirdly, that doesn't work. |
If you pinned the plugin to 0.2.1 then that makes sense, the changes haven't been released yet |
@noomly Yeah, that was my mistake. Silly. Got it working now! 👍🏼 |
No description provided.