feat: prioritize jump labels by distance from cursor
scan() returns matches in top-to-bottom reading order. With the 26-label cap, that meant the first 26 matches on screen ate all the labels — your cursor could be at the bottom of the buffer and still have no labels near it. Sort matches by |line - cursor_line|, then by |col - cursor_col| as tie-break, before label assignment. Labels now land on the 26 closest matches rather than the 26 topmost. Same label pool, same public API, big UX win for any buffer with more hits than labels.
This commit is contained in:
1 file changed
+9
@@ -102,6 +102,15 @@ function M.start()
|
|||||||
|
|
||||||
if #chars > 0 then
|
if #chars > 0 then
|
||||||
local matches, avail = scan(chars, lines, top)
|
local matches, avail = scan(chars, lines, top)
|
||||||
|
local cr = api.nvim_win_get_cursor(win)
|
||||||
|
local cl, cc = cr[1] - 1, cr[2]
|
||||||
|
table.sort(matches, function(a, b)
|
||||||
|
local da, db = math.abs(a.line - cl), math.abs(b.line - cl)
|
||||||
|
if da ~= db then
|
||||||
|
return da < db
|
||||||
|
end
|
||||||
|
return math.abs(a.start_col - cc) < math.abs(b.start_col - cc)
|
||||||
|
end)
|
||||||
local li = 1
|
local li = 1
|
||||||
for _, m in ipairs(matches) do
|
for _, m in ipairs(matches) do
|
||||||
vim.hl.range(
|
vim.hl.range(
|
||||||
|
|||||||
Reference in new issue
Block a user