Skip to content

Commit

Permalink
fix!: drop specialized text highlight groups (#30)
Browse files Browse the repository at this point in the history
Removing DressingInputText and DressingSelectText highlight groups that
were added for #8. I added them before I learned about winhighlight, and
it turns out that winhighlight is the better way to do this. Previously
I was using `nvim_buf_add_highlight` to directly add the highlight
group, but that has multiple downsides (can't highlight bg of regions
with no text, overrides other relevate highlight groups e.g.
CursorLine). None of that is needed because Neovim will be setting the
highlight group of this text to NormalFloat, and if the user wants to
customize it we already expose an easy option in config to do
`winhighlight = "NormalFloat:MyCustomHighlightGroup"`.
  • Loading branch information
stevearc committed Mar 30, 2022
1 parent 31f12ff commit e14e35a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
14 changes: 9 additions & 5 deletions lua/dressing/input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,10 @@ M.highlight = function()
local opts = context.opts
local text = vim.api.nvim_buf_get_lines(bufnr, 0, 1, true)[1]
local ns = vim.api.nvim_create_namespace("DressingHighlight")
local highlights
if not opts.highlight then
highlights = { { 0, -1, "DressingInputText" } }
elseif type(opts.highlight) == "function" then
local highlights = {}
if type(opts.highlight) == "function" then
highlights = opts.highlight(text)
else
elseif opts.highlight then
highlights = vim.fn[opts.highlight](text)
end
vim.api.nvim_buf_clear_namespace(bufnr, ns, 0, -1)
Expand Down Expand Up @@ -246,6 +244,12 @@ setmetatable(M, {
if not config.enabled then
return patch.original_mods.input(opts, on_confirm)
end
if vim.fn.hlID("DressingInputText") ~= 0 then
vim.notify(
'DressingInputText highlight group is deprecated. Set winhighlight="NormalFloat:MyHighlightGroup" instead',
vim.log.levels.WARN
)
end

-- Create or update the window
local prompt = opts.prompt or config.default_prompt
Expand Down
10 changes: 6 additions & 4 deletions lua/dressing/select/builtin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ local function clear_callback()
end

M.select = function(config, items, opts, on_choice)
if vim.fn.hlID("DressingSelectText") ~= 0 then
vim.notify(
'DressingSelectText highlight group is deprecated. Set winhighlight="NormalFloat:MyHighlightGroup" instead',
vim.log.levels.WARN
)
end
_callback = on_choice
_items = items
local bufnr = vim.api.nvim_create_buf(false, true)
Expand All @@ -27,10 +33,6 @@ M.select = function(config, items, opts, on_choice)
end
vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, lines)
vim.api.nvim_buf_set_option(bufnr, "modifiable", false)
local ns = vim.api.nvim_create_namespace("DressingWindow")
for i = 0, #lines - 1, 1 do
vim.api.nvim_buf_add_highlight(bufnr, ns, "DressingSelectText", i, 0, -1)
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
2 changes: 0 additions & 2 deletions plugin/dressing.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
require("dressing").patch()
vim.cmd([[highlight default link FloatTitle FloatBorder]])
vim.cmd([[highlight default link DressingSelectText NormalFloat]])
vim.cmd([[highlight default link DressingInputText NormalFloat]])

0 comments on commit e14e35a

Please sign in to comment.