Skip to content

Commit

Permalink
Fix highlighting when pasting multiple lines
Browse files Browse the repository at this point in the history
The solution was to do the highlighting for each change independently.
The problem is that the match trees of different changes overlap, which
can cause a node to be considered its own child when assembling the
final match tree.
  • Loading branch information
HiPhish committed Sep 5, 2024
1 parent 7bdae43 commit efda387
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lua/rainbow-delimiters/strategy/global2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ local function update_range(bufnr, changes, tree, lang)
if not query then return end

---Temporary stack of partial match trees; used to build the final match trees
local match_trees = Stack.new()
local root_node = tree:root()

-- Build the match tree
for _, change in ipairs(changes) do
local match_trees = Stack.new()
local start_row, end_row = change[1], change[3] + 1
lib.clear_namespace(bufnr, lang, start_row, end_row)

Expand All @@ -79,10 +79,9 @@ local function update_range(bufnr, changes, tree, lang)
end
match_trees:push(this)
end
end

for _, match_tree in match_trees:iter() do
MatchTree.highlight(match_tree, bufnr, lang, 1)
for _, match_tree in match_trees:iter() do
MatchTree.highlight(match_tree, bufnr, lang, 1)
end
end
end

Expand Down

0 comments on commit efda387

Please sign in to comment.