Skip to content

Commit

Permalink
fix(find): normalize only matched nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
b-coimbra committed Jun 16, 2022
1 parent d448ff6 commit 1176de6
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions content_scripts/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ Find.highlight = function(params) {
linksOnly = false;

markBase.className = 'cVim-find-mark';
// markBase.id = Math.floor(Math.random() * 1e4);

this.mode = params.mode || '/';
if (params.saveSearch)
Expand Down Expand Up @@ -239,10 +240,19 @@ Find.highlight = function(params) {
};

Find.clear = function() {
var nodes = this.matches;
for (var i = 0; i < nodes.length; i++)
if (nodes[i] && nodes[i].parentNode && nodes[i].firstChild)
nodes[i].parentNode.replaceChild(nodes[i].firstChild, nodes[i]);
document.documentElement.normalize();
const nodes = this.matches;
let nodesToNormalize = [];

for (let i = 0; i < nodes.length; i++) {
const { parentNode, firstChild } = nodes[i];

if (nodes[i] && parentNode && firstChild) {
nodesToNormalize.push(parentNode);
parentNode.replaceChild(firstChild, nodes[i]);
}
}

nodesToNormalize.forEach(node => node.normalize());

this.matches = [];
};

1 comment on commit 1176de6

@b-coimbra
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit fixes 1995eaton/chromium-vim#751

Please sign in to comment.