Skip to content

Commit

Permalink
feat(highlight): added option to disable distance based labeling
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jun 26, 2023
1 parent 471b165 commit ad9212f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lua/flash/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ local defaults = {
-- flash tries to re-use labels that were already assigned to a position,
-- when typing more characters. By default only lower-case labels are re-used.
reuse = "lowercase", ---@type "lowercase" | "all"
-- for the current window, label targets closer to the cursor first
distance = true,
},
-- show a backdrop with hl FlashBackdrop
backdrop = true,
Expand Down
6 changes: 4 additions & 2 deletions lua/flash/labeler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,22 @@ function M:filter()

-- sort by current win, other win, then by distance
table.sort(ret, function(a, b)
local use_distance = self.state.opts.highlight.label.distance and a.win == self.state.win

if a.win ~= b.win then
local aw = a.win == self.state.win and 0 or a.win
local bw = b.win == self.state.win and 0 or b.win
return aw < bw
end
if a.pos[1] ~= b.pos[1] then
if a.win == self.state.win then
if use_distance then
local da = math.abs(a.pos[1] - from[1])
local db = math.abs(b.pos[1] - from[1])
return da < db
end
return a.pos[1] < b.pos[1]
end
if a.win == self.state.win then
if use_distance then
local da = math.abs(a.pos[2] - from[2])
local db = math.abs(b.pos[2] - from[2])
return da < db
Expand Down

0 comments on commit ad9212f

Please sign in to comment.