Skip to content

Commit

Permalink
feat: add highlight group for builtin select index (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Aug 19, 2023
1 parent 59fe7ef commit ee57150
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lua/dressing/select/builtin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ M.select = function(config, items, opts, on_choice)
vim.bo[bufnr][k] = v
end
local lines = {}
local highlights = {}
local max_width = 1
for idx, item in ipairs(items) do
local line = "[" .. idx .. "] " .. opts.format_item(item)
local prefix = "[" .. idx .. "] "
table.insert(highlights, { #lines, prefix:len() })
local line = prefix .. opts.format_item(item)
max_width = math.max(max_width, vim.api.nvim_strwidth(line))
table.insert(lines, line)

Expand All @@ -70,6 +73,11 @@ M.select = function(config, items, opts, on_choice)
end
vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, lines)
vim.bo[bufnr].modifiable = false
local ns = vim.api.nvim_create_namespace("DressingSelect")
for _, hl in ipairs(highlights) do
local lnum, end_col = unpack(hl)
vim.api.nvim_buf_add_highlight(bufnr, ns, "DressingSelectIdx", lnum, 0, end_col)
end
local width = util.calculate_width(config.relative, max_width, config, 0)
local height = util.calculate_height(config.relative, #lines, config, 0)
local row = util.calculate_row(config.relative, height, 0)
Expand Down
4 changes: 3 additions & 1 deletion plugin/dressing.lua
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
require("dressing").patch()
vim.cmd([[highlight default link FloatTitle FloatBorder]])
vim.api.nvim_set_hl(0, "DressingSelectIdx", {
link = "Special",
})

0 comments on commit ee57150

Please sign in to comment.