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

Skip select_next for single item #242

Closed
andrewferrier opened this issue Nov 2, 2024 · 3 comments
Closed

Skip select_next for single item #242

andrewferrier opened this issue Nov 2, 2024 · 3 comments
Labels
feature New feature or request

Comments

@andrewferrier
Copy link

It would be nice to be able to have a completion key which, when there is more than one match, scrolls downward through the list (like select_next) but when there is only one match, accepts it (like select_and_accept). I've tried chaining these like this:

        ["<Tab>"] = { "select_next", "select_and_accept", "fallback" },

... but that didn't work how I expected, it just acts like select_next even when there is only one match available. I am using to completion being very simple and it's tricky to get used to have to use different keys for these.

This is similar to (but not identical to) the menu option for NeoVim's built-in completeopt.

@Saghen Saghen changed the title Feature Request: Would be nice to be able to combine select_next and select_and_accept Skip select_next for single item Nov 2, 2024
@Saghen Saghen added the feature New feature or request label Nov 2, 2024
@Jezda1337
Copy link
Contributor

Should this be handled by the plugin itself, or should we provide an API with the length of the items so the user can perform actions like this? @Saghen

  --   ['<Tab>'] = {
  --     function(cmp)
  --       if #cmp.items == 1 then return cmp.accept() end
  --       if cmp.is_in_snippet() then return cmp.accept()
  --       else return cmp.select_and_accept() end
  --     end,
  --     'snippet_forward',
  --     'fallback'
  --   },

@Saghen
Copy link
Owner

Saghen commented Nov 3, 2024

I think the latter. It's possible right now with #cmp.windows.autocomplete.items but that's an internal API which won't be exposed long term. Ideally the list isnt coupled with the autocomplete window, and instead, moved into a separate module, which also handles selection.

@Saghen Saghen closed this as completed in dc267e0 Feb 20, 2025
@Saghen
Copy link
Owner

Saghen commented Feb 20, 2025

You may now write your own function for this using require('blink.cmp').get_items() and require('blink.cmp').get_selected_item_idx(). Please share what you come up with!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants