Skip to content

Commit

Permalink
feat: add preselect support
Browse files Browse the repository at this point in the history
fixes #60
  • Loading branch information
max397574 committed Aug 2, 2024
1 parent 3cd8202 commit f949bb3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ The `completion_events` table is used to set events for completion. By default i

TODO

## Preselect

Whether items should be preselected or not

## Enabled

This function can be used to disable care in certain contexts. By default this disables
Expand Down
1 change: 1 addition & 0 deletions lua/care/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ config.defaults = {
selection_behavior = "select",
keyword_pattern = [[\%(-\?\d\+\%(\.\d\+\)\?\|\h\w*\%(-\w*\)*\)]],
sources = {},
preselect = true,
completion_events = { "TextChangedI" },
enabled = function()
local enabled = true
Expand Down
9 changes: 9 additions & 0 deletions lua/care/menu/draw.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,13 @@ return function(self)
vim.api.nvim_buf_add_highlight(self.menu_window.buf, self.ns, "@care.match", line - 1, idx - 1, idx)
end
end
if not self.config.preselect then
return
end
for index, entry in ipairs(self.entries) do
if entry.completion_item.preselect then
self.index = index
break
end
end
end
4 changes: 3 additions & 1 deletion lua/care/types/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
---@field keyword_pattern string
--- Configuration for the ui of care
---@field enabled fun(): boolean
--- The main class for the ui configuration of care.nvim
--- Whether items should be preselected or not
---@field preselect boolean

--- The main class for the ui configuration of care.nvim
---@class care.config.ui
--- Configuration of the completion menu of care.nvim
---@field menu care.config.ui.menu
Expand Down

0 comments on commit f949bb3

Please sign in to comment.