diff --git a/docs/configuration/reference.md b/docs/configuration/reference.md index 28dd449e..2dea8e8a 100644 --- a/docs/configuration/reference.md +++ b/docs/configuration/reference.md @@ -185,7 +185,7 @@ completion.menu = { -- Controls how the completion items are rendered on the popup window completion.menu.draw = { -- Aligns the keyword you've typed to a component in the menu - align_to_component = 'label', -- or 'none' to disable + align_to = 'label', -- or 'none' to disable, or 'cursor' to align to the cursor -- Left and right padding, optionally { left, right } for different padding on each side padding = 1, -- Gap between columns diff --git a/lua/blink/cmp/completion/windows/menu.lua b/lua/blink/cmp/completion/windows/menu.lua index 969f99ed..e2ac8bce 100644 --- a/lua/blink/cmp/completion/windows/menu.lua +++ b/lua/blink/cmp/completion/windows/menu.lua @@ -106,7 +106,7 @@ function menu.update_position() return end - local start_col = menu.renderer:get_alignment_start_col() + local alignment_start_col = menu.renderer:get_alignment_start_col() -- place the window at the start col of the current text we're fuzzy matching against -- so the window doesnt move around as we type @@ -117,12 +117,19 @@ function menu.update_position() win:set_win_config({ relative = 'editor', row = cmdline_position[1] + row, - col = math.max(cmdline_position[2] + context.bounds.start_col - start_col, 0), + col = math.max(cmdline_position[2] + context.bounds.start_col - alignment_start_col, 0), }) else local cursor_col = context.get_cursor()[2] - local col = context.bounds.start_col - cursor_col - (context.bounds.length == 0 and 0 or 1) - border_size.left - win:set_win_config({ relative = 'cursor', row = row, col = col - start_col }) + + local col = context.bounds.start_col + - alignment_start_col + - cursor_col + - (context.bounds.length == 0 and 0 or 1) + - border_size.left + if config.draw.align_to == 'cursor' then col = 0 end + + win:set_win_config({ relative = 'cursor', row = row, col = col - alignment_start_col }) end win:set_height(pos.height) diff --git a/lua/blink/cmp/completion/windows/render/init.lua b/lua/blink/cmp/completion/windows/render/init.lua index 70fa7ba5..1422ec2e 100644 --- a/lua/blink/cmp/completion/windows/render/init.lua +++ b/lua/blink/cmp/completion/windows/render/init.lua @@ -138,8 +138,8 @@ function renderer:get_component_start_col(component_name) end function renderer:get_alignment_start_col() - local component_name = self.def.align_to_component - if component_name == nil or component_name == 'none' then return 0 end + local component_name = self.def.align_to + if component_name == nil or component_name == 'none' or component_name == 'cursor' then return 0 end return self:get_component_start_col(component_name) end diff --git a/lua/blink/cmp/completion/windows/render/types.lua b/lua/blink/cmp/completion/windows/render/types.lua index b9cb4bf1..186b3dc3 100644 --- a/lua/blink/cmp/completion/windows/render/types.lua +++ b/lua/blink/cmp/completion/windows/render/types.lua @@ -1,5 +1,5 @@ --- @class blink.cmp.Draw ---- @field align_to_component? string | 'none' Align the window to the component with the given name +--- @field align_to? string | 'none' | 'cursor' Align the window to the component with the given name, or to the cursor --- @field padding? number | number[] Padding on the left and right of the grid --- @field gap? number Gap between columns --- @field columns? { [number]: string, gap?: number }[] Components to render, grouped by column diff --git a/lua/blink/cmp/config/completion/menu.lua b/lua/blink/cmp/config/completion/menu.lua index d7469255..60c0f627 100644 --- a/lua/blink/cmp/config/completion/menu.lua +++ b/lua/blink/cmp/config/completion/menu.lua @@ -55,7 +55,7 @@ local window = { -- Controls how the completion items are rendered on the popup window draw = { -- Aligns the keyword you've typed to a component in the menu - align_to_component = 'label', -- or 'none' to disable + align_to = 'cursor', -- or 'none' to disable -- Left and right padding, optionally { left, right } for different padding on each side padding = 1, -- Gap between columns @@ -161,10 +161,10 @@ function window.validate(config) }, config.order) validate('completion.menu.draw', { - align_to_component = { - config.draw.align_to_component, + align_to = { + config.draw.align_to, function(align) - if align == 'none' then return true end + if align == 'none' or align == 'cursor' then return true end for _, column in ipairs(config.draw.columns) do for _, component in ipairs(column) do if component == align then return true end