diff --git a/apps/desktop/src/lib/find-in-page-scope.test.ts b/apps/desktop/src/lib/find-in-page-scope.test.ts index 3741fcf8b2..bc0d75e904 100644 --- a/apps/desktop/src/lib/find-in-page-scope.test.ts +++ b/apps/desktop/src/lib/find-in-page-scope.test.ts @@ -205,6 +205,21 @@ describe('performScopedFind', () => { expect(result.activeOrdinal).toBe(2) expect(surface.querySelectorAll('mark.find-hit').length).toBe(2) }) + + it('keeps searching sibling subtrees after a fully-consumed text node', () => { + // Regression (#81778 review): a text node that was entirely consumed by + // a match used to null the walker's `current`, terminating the sibling + // traversal — `
needle
' + ) + const result = performScopedFind(surface, 'needle', { forward: true, findNext: false }) + + expect(result.count).toBe(3) + expect(surface.querySelectorAll('mark.find-hit').length).toBe(3) + }) }) describe('scope lifecycle', () => { diff --git a/apps/desktop/src/lib/find-in-page-scope.ts b/apps/desktop/src/lib/find-in-page-scope.ts index 7d21222af7..a2dcafb3ac 100644 --- a/apps/desktop/src/lib/find-in-page-scope.ts +++ b/apps/desktop/src/lib/find-in-page-scope.ts @@ -150,6 +150,13 @@ function highlightMatches(root: Element, query: string): HTMLElement[] { // Search within this text node. Splits may invalidate `textNode`'s // identity, so we re-read it from the parent each iteration. let nodeValue = textNode.nodeValue ?? '' + // Capture the text node's own next sibling BEFORE any replaceChild: + // once the original node is detached, `.nextSibling` reads null and + // the outer walker would stop, skipping every following sibling + // subtree (`