Skip to content

Commit

Permalink
feat!: change config of auto_insert,preselect to a single 'selection'
Browse files Browse the repository at this point in the history
  • Loading branch information
noomly committed Oct 10, 2024
1 parent 806f37c commit 77c75cd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions lua/blink/cmp/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@
--- @field border? blink.cmp.WindowBorder
--- @field order? "top_down" | "bottom_up"
--- @field direction_priority? ("n" | "s")[]
--- @field preselect? boolean
--- @field auto_insert? boolean
--- @field selection? "preselect" | "manual" | "auto_insert"
--- @field winhighlight? string
--- @field scrolloff? number
--- @field draw? 'simple' | 'reversed' | function(blink.cmp.CompletionRenderContext): blink.cmp.Component[]
Expand Down Expand Up @@ -247,10 +246,11 @@ local config = {
-- which directions to show the window,
-- falling back to the next direction when there's not enough space
direction_priority = { 's', 'n' },
-- whether to preselect the first item in the completion list
preselect = true,
-- Whether to insert the completion items automatically when selecting them. Requires `preselect = false`
auto_insert = true,
-- Controls how the completion items are selected
-- 'preselect' will automatically select the first item in the completion list
-- 'manual' will not select any item by default
-- 'auto_insert' will not select any item by default, and insert the completion items automatically when selecting them
selection = 'preselect',
-- Controls how the completion items are rendered on the popup window
-- 'simple' will render the item's kind icon the left alongside the label
-- 'reversed' will render the label on the left and the kind icon + name on the right
Expand Down
2 changes: 1 addition & 1 deletion lua/blink/cmp/trigger/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function trigger.activate_autocmds()
and not vim.tbl_contains(config_trigger.show_on_insert_blocked_trigger_characters, char_under_cursor)
local is_on_context_char = char_under_cursor:match(config_trigger.keyword_regex) ~= nil

if config.windows.autocomplete.auto_insert and trigger.triggered_by ~= 'select' then
if config.windows.autocomplete.selection == 'auto_insert' and trigger.triggered_by ~= 'select' then
if is_within_bounds then
trigger.show()
elseif
Expand Down
8 changes: 4 additions & 4 deletions lua/blink/cmp/windows/autocomplete.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function autocomplete.open_with_items(context, items)

autocomplete.context = context
autocomplete.update_position(context)
autocomplete.set_has_selected(autocmp_config.preselect)
autocomplete.set_has_selected(autocmp_config.selection == 'preselect')

-- todo: some logic to maintain the selection if the user moved the cursor?
vim.api.nvim_win_set_cursor(autocomplete.win:get_win(), { 1, 0 })
Expand All @@ -76,13 +76,13 @@ end
function autocomplete.open()
if autocomplete.win:is_open() then return end
autocomplete.win:open()
autocomplete.set_has_selected(autocmp_config.preselect)
autocomplete.set_has_selected(autocmp_config.selection == 'preselect')
end

function autocomplete.close()
if not autocomplete.win:is_open() then return end
autocomplete.win:close()
autocomplete.has_selected = autocmp_config.preselect
autocomplete.has_selected = autocmp_config.selection == 'preselect'
autocomplete.event_targets.on_close()
end
function autocomplete.listen_on_close(callback) autocomplete.event_targets.on_close = callback end
Expand Down Expand Up @@ -140,7 +140,7 @@ end

--- @param line number
local function select(line)
local auto_insert = config.windows.autocomplete.auto_insert
local auto_insert = config.windows.autocomplete.selection == 'auto_insert'

local prev_selected_item = autocomplete.get_selected_item()

Expand Down

0 comments on commit 77c75cd

Please sign in to comment.