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

Feature: If completion window is positioned above cursor, display results from bottom-up #910

Closed
b0o opened this issue Apr 17, 2022 · 2 comments

Comments

@b0o
Copy link

b0o commented Apr 17, 2022

When the cursor is near the bottom of the window, or when completing cmdlines/searches, the completion window appears above the cursor. It would be nice to have an option to display results starting from the bottom of the completion window in these cases.

It makes sense to me that the best match should be nearest the cursor, to minimize eye movement and scanning. This would also mean that the window should start scrolled to the bottom.

Related: #495

@hrsh7th
Copy link
Owner

hrsh7th commented Apr 18, 2022

This is implemented (as an unstable undocumented feature) recently.

    view = {
      entries = { name = 'custom', selection_order = 'bottom_up' }
    },

@hrsh7th hrsh7th closed this as completed Apr 18, 2022
@b0o
Copy link
Author

b0o commented Apr 18, 2022

Oh, awesome, thank you! This almost works exactly how I wanted – but I prefer <C-n> to always go "down" and <C-p> to always go "up". So I wrote these mappings which do the job:

mapping = cmp.mapping.preset.insert {
 ['<C-n>'] = function(fallback)
   if cmp.visible() then
     if cmp.core.view.custom_entries_view:is_direction_top_down() then
       cmp.select_next_item()
     else
       cmp.select_prev_item()
     end
   else
     fallback()
   end
 end,
 ['<C-p>'] = function(fallback)
   if cmp.visible() then
     if cmp.core.view.custom_entries_view:is_direction_top_down() then
       cmp.select_prev_item()
     else
       cmp.select_next_item()
     end
   else
     fallback()
   end
 end,
}

(sorry for using your private APIs 😉)

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

2 participants