Skip to content

Commit

Permalink
feat(api): allow a match to enable/disable highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jun 26, 2023
1 parent ea56cea commit 38eca97
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ interface FlashMatch {
pos: [number, number]; // (1,0)-indexed
end_pos: [number, number]; // (1,0)-indexed
label?: string | false; // set to false to never show a label for this match
highlight?: boolean; // override opts.highlight.matches for this match
}

// Check the code for the full definition
Expand Down
7 changes: 6 additions & 1 deletion lua/flash/highlight.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,12 @@ function M.update(state)
for _, match in ipairs(state.results) do
local buf = vim.api.nvim_win_get_buf(match.win)

if state.opts.highlight.matches then
local highlight = state.opts.highlight.matches
if match.highlight ~= nil then
highlight = match.highlight
end

if highlight then
vim.api.nvim_buf_set_extmark(buf, state.ns, match.pos[1] - 1, match.pos[2], {
end_row = match.end_pos[1] - 1,
end_col = match.end_pos[2] + 1,
Expand Down
1 change: 1 addition & 0 deletions lua/flash/search/matcher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local Pos = require("flash.search.pos")
---@field pos Pos -- (1,0) indexed
---@field end_pos Pos -- (1,0) indexed
---@field label? string|false
---@field highlight? boolean

---@alias Flash.Match.Find {forward?:boolean, wrap?:boolean, count?:number, pos?: Pos, match?:Flash.Match}

Expand Down

0 comments on commit 38eca97

Please sign in to comment.