Skip to content

Commit

Permalink
feat: highlight groups config
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jun 9, 2023
1 parent 3e6b345 commit 313e252
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 6 additions & 0 deletions lua/flash/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ local defaults = {
matches = true,
-- extmark priority
priority = 5000,
groups = {
match = "FlashMatch",
current = "FlashCurrent",
backdrop = "FlashBackdrop",
label = "FlashLabel",
},
},
-- You can override the default options for a specific mode.
-- Use it with `require("flash").jump({mode = "forward"})`
Expand Down
8 changes: 4 additions & 4 deletions lua/flash/highlight.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function M.backdrop(state)
-- extmarks priority rendering works
for line = from[1], to[1] do
vim.api.nvim_buf_set_extmark(buf, M.ns, line - 1, line == from[1] and from[2] or 0, {
hl_group = "FlashBackdrop",
hl_group = state.config.highlight.groups.backdrop,
end_row = line == to[1] and line - 1 or line,
hl_eol = line ~= to[1],
end_col = line == to[1] and to[2] or from[2],
Expand All @@ -52,22 +52,22 @@ function M.update(state)
M.backdrop(state)
end

for _, match in ipairs(state.results) do
for m, match in ipairs(state.results) do
local buf = vim.api.nvim_win_get_buf(match.win)

if state.config.highlight.matches then
vim.api.nvim_buf_set_extmark(buf, M.ns, match.from[1] - 1, match.from[2], {
end_row = match.to[1] - 1,
end_col = match.to[2] + 1,
hl_group = match.current and match.win == state.win and "FlashCurrent" or "FlashMatch",
hl_group = state.current == m and state.config.highlight.groups.current or state.config.highlight.groups.match,
strict = false,
priority = state.config.highlight.priority + 1,
})
end

if match.label then
vim.api.nvim_buf_set_extmark(buf, M.ns, match.to[1] - 1, match.to[2] + 1, {
virt_text = { { match.label, "FlashLabel" } },
virt_text = { { match.label, state.config.highlight.groups.label } },
virt_text_pos = "overlay",
strict = false,
priority = state.config.highlight.priority + 2,
Expand Down

0 comments on commit 313e252

Please sign in to comment.