Skip to content

Commit a9af185

Browse files
authored
fix: batch normalize() calls in clearTextHighlights to prevent tab fr… (#47)
…eeze fixes #41 Before: tab froze when deleting final character in "find in file" command After: deleting final character works find due to batched normalizing of highlighting.
1 parent e087179 commit a9af185

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

apps/web/src/components/repo/code-viewer-client.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,16 @@ interface SearchMatch {
4545

4646
function clearTextHighlights(container: Element) {
4747
const marks = container.querySelectorAll("mark.search-text-match");
48+
if (marks.length === 0) return;
49+
const parents = new Set<Node>();
4850
marks.forEach((mark) => {
4951
const parent = mark.parentNode;
5052
if (parent) {
53+
parents.add(parent);
5154
parent.replaceChild(document.createTextNode(mark.textContent || ""), mark);
52-
parent.normalize();
5355
}
5456
});
57+
parents.forEach((parent) => (parent as Element).normalize());
5558
}
5659

5760
function highlightTextInLine(lineEl: Element, query: string, caseSensitive: boolean) {

0 commit comments

Comments
 (0)