-
Notifications
You must be signed in to change notification settings - Fork 436
feat: config.view.entries.vertical_positioning = 'above'|'below'|'auto'
#1701
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
Changes from all commits
90a3c63
d63ad77
948ed0a
6daaa5f
965dc82
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ local DEFAULT_HEIGHT = 10 -- @see https://github.com/vim/vim/blob/master/src/pop | |
| ---@field private active boolean | ||
| ---@field private entries cmp.Entry[] | ||
| ---@field private column_width any | ||
| ---@field private bottom_up boolean | ||
| ---@field public event cmp.Event | ||
| local custom_entries_view = {} | ||
|
|
||
|
|
@@ -117,7 +118,8 @@ custom_entries_view.is_direction_top_down = function(self) | |
| end | ||
|
|
||
| custom_entries_view.open = function(self, offset, entries) | ||
| local completion = config.get().window.completion | ||
| local c = config.get() | ||
| local completion = c.window.completion | ||
| assert(completion, 'config.get() must resolve window.completion with defaults') | ||
|
|
||
| self.offset = offset | ||
|
|
@@ -172,12 +174,25 @@ custom_entries_view.open = function(self, offset, entries) | |
| local border_info = window.get_border_info({ style = completion }) | ||
| local border_offset_row = border_info.top + border_info.bottom | ||
| local border_offset_col = border_info.left + border_info.right | ||
| if math.floor(vim.o.lines * 0.5) <= row + border_offset_row and vim.o.lines - row - border_offset_row <= math.min(DEFAULT_HEIGHT, height) then | ||
|
|
||
| local prefers_above = c.view.entries.vertical_positioning == 'above' | ||
| local prefers_auto = c.view.entries.vertical_positioning == 'auto' | ||
| local cant_fit_at_bottom = vim.o.lines - row - border_offset_row <= math.min(DEFAULT_HEIGHT, height) | ||
| local cant_fit_at_top = row - border_offset_row <= math.min(DEFAULT_HEIGHT, height) | ||
| local is_in_top_half = math.floor(vim.o.lines * 0.5) > row + border_offset_row | ||
| local should_position_above = | ||
| cant_fit_at_bottom or | ||
| (prefers_above and not cant_fit_at_top) or | ||
| (prefers_auto and is_in_top_half) | ||
| if should_position_above then | ||
| self.bottom_up = true | ||
| height = math.min(height, row - 1) | ||
| row = row - height - border_offset_row - 1 | ||
| if row < 0 then | ||
| height = height + row | ||
| end | ||
| else | ||
| self.bottom_up = false | ||
| end | ||
|
Comment on lines
+178
to
196
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be cool if this code some how took into account the experimental ghost text feature. Not sure if it can be done, but i would like to see auto checking if the ghost text is more than a number of lines that could maybe be configured as well. Could also just be set to 1 line. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess you mean #1955 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ye that about covers it :) |
||
| if math.floor(vim.o.columns * 0.5) <= col + border_offset_col and vim.o.columns - col - border_offset_col <= width then | ||
| width = math.min(width, vim.o.columns - 1) | ||
|
|
@@ -187,12 +202,6 @@ custom_entries_view.open = function(self, offset, entries) | |
| end | ||
| end | ||
|
|
||
| if pos[1] > row then | ||
| self.bottom_up = true | ||
| else | ||
| self.bottom_up = false | ||
| end | ||
|
|
||
| if not self:is_direction_top_down() then | ||
| local n = #self.entries | ||
| for i = 1, math.floor(n / 2) do | ||
|
|
@@ -226,9 +235,9 @@ custom_entries_view.open = function(self, offset, entries) | |
|
|
||
| -- Always set cursor when starting. It will be adjusted on the call to _select | ||
| vim.api.nvim_win_set_cursor(self.entries_win.win, { 1, 0 }) | ||
| if preselect_index > 0 and config.get().preselect == types.cmp.PreselectMode.Item then | ||
| if preselect_index > 0 and c.preselect == types.cmp.PreselectMode.Item then | ||
| self:_select(preselect_index, { behavior = types.cmp.SelectBehavior.Select, active = false }) | ||
| elseif not string.match(config.get().completion.completeopt, 'noselect') then | ||
| elseif not string.match(c.completion.completeopt, 'noselect') then | ||
| if self:is_direction_top_down() then | ||
| self:_select(1, { behavior = types.cmp.SelectBehavior.Select, active = false }) | ||
| else | ||
|
|
||
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'm somewhat unsure of what the selection order does, but i imagine it choose if the most relevant entry is shown at the top of the list or nearest the cursor. could be a good place to add a bottom up option as its only become useful now with this new feature for vertical positioning