Skip to content

Commit e52e04f

Browse files
committed
Fix infinite single line highlight bug (#45)
1 parent 5a11631 commit e52e04f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lua/treewalker/operations.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ end
3939
---@param hl_group string
4040
function M.highlight(range, duration, hl_group)
4141
local start_row, start_col, end_row, end_col = range[1], range[2], range[3], range[4]
42-
local ns_name = "treewalker.nvim-movement-highlight-" .. util.guid()
42+
local ns_prefix = "treewalker.nvim-movement-highlight-"
43+
local ns_name = ns_prefix .. util.guid()
4344
local local_ns_id = vim.api.nvim_create_namespace(ns_name)
4445

4546
-- clear any previous highlights so there aren't multiple active at the same time
4647
-- Find them by prefix, whole local name will only be used for timeout below
4748
for name, id in pairs(vim.api.nvim_get_namespaces()) do
48-
if name:match("^treewalker") then
49+
if vim.startswith(name, ns_prefix) then
4950
vim.api.nvim_buf_clear_namespace(0, id, 0, -1)
5051
end
5152
end
@@ -70,7 +71,7 @@ function M.highlight(range, duration, hl_group)
7071

7172
-- Remove the local highlight after delay
7273
vim.defer_fn(function()
73-
vim.api.nvim_buf_clear_namespace(0, local_ns_id, start_row, end_row)
74+
vim.api.nvim_buf_clear_namespace(0, local_ns_id, start_row, end_row + 1)
7475
end, duration)
7576
end
7677

0 commit comments

Comments
 (0)