Skip to content

Commit

Permalink
feat: config option to disable numbers for builtin select implementat…
Browse files Browse the repository at this point in the history
…ion (#117)
  • Loading branch information
stevearc committed Sep 5, 2023
1 parent b1c7b70 commit 15ef9a3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
2 changes: 2 additions & 0 deletions lua/dressing/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ local default_config = {

-- Options for built-in selector
builtin = {
-- Display numbers for options and set up keymaps
show_numbers = true,
-- These are passed to nvim_open_win
border = "rounded",
-- 'editor' and 'win' will default to being centered
Expand Down
23 changes: 13 additions & 10 deletions lua/dressing/select/builtin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,22 @@ M.select = function(config, items, opts, on_choice)
local highlights = {}
local max_width = 1
for idx, item in ipairs(items) do
local prefix = "[" .. idx .. "] "
table.insert(highlights, { #lines, prefix:len() })
local prefix = ""
if config.show_numbers then
prefix = "[" .. idx .. "] "
table.insert(highlights, { #lines, prefix:len() })

vim.api.nvim_buf_set_keymap(bufnr, "n", tostring(idx), "", {
callback = function()
local callback, local_items = close_window()
local target_item = local_items[idx]
callback(target_item, idx)
end,
})
end
local line = prefix .. opts.format_item(item)
max_width = math.max(max_width, vim.api.nvim_strwidth(line))
table.insert(lines, line)

vim.api.nvim_buf_set_keymap(bufnr, "n", tostring(idx), "", {
callback = function()
local callback, local_items = close_window()
local target_item = local_items[idx]
callback(target_item, idx)
end,
})
end
vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, lines)
vim.bo[bufnr].modifiable = false
Expand Down

0 comments on commit 15ef9a3

Please sign in to comment.