fix(desktop): case-insensitive fast-path in find-in-page stepping (#81778)
Triage found the findNext fast path compared each existing `<mark>`'s
textContent byte-for-byte against the typed query. Since highlightMatches
stores the ORIGINAL-CASE source slice, the first differently-cased match
('Hermes' for 'hermes', sentence-initial capitals, ALL-CAPS) failed the
check, forcing a full re-wrap on every Enter/⌘G: fresh `<mark>` elements
lose `data-find-active`, `previousActive` resolves null, and the active
ordinal stays 1 forever (backward steps land on the last match every
time).
Compare case-insensitively. Regression test pins the differently-cased
stepping behavior: same marks survive, count stays 2, ordinal advances
to 2.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -149,6 +149,24 @@ describe('performScopedFind', () => {
|
||||
expect(result.activeOrdinal).toBe(2)
|
||||
})
|
||||
|
||||
it('does not re-wrap when the query differs only in case (fast path, triage #81778)', () => {
|
||||
// The marks store the ORIGINAL-CASE source slice, so a byte-equality
|
||||
// fast-path check fails on the first differently-cased match and every
|
||||
// Enter re-wraps, losing `data-find-active` and pinning the ordinal to
|
||||
// 1 forever. Case-insensitive comparison keeps stepping.
|
||||
const surface = plantSurface('surface', '<p>Hermes Hermes</p>')
|
||||
performScopedFind(surface, 'hermes', { forward: true, findNext: false })
|
||||
|
||||
const before = [...surface.querySelectorAll('mark.find-hit')]
|
||||
const result = performScopedFind(surface, 'hermes', { forward: true, findNext: true })
|
||||
|
||||
const after = [...surface.querySelectorAll('mark.find-hit')]
|
||||
expect(after.length).toBe(before.length)
|
||||
expect(after.every(el => before.includes(el))).toBe(true)
|
||||
expect(result.count).toBe(2)
|
||||
expect(result.activeOrdinal).toBe(2)
|
||||
})
|
||||
|
||||
it('re-wraps when the query changes (marks are not reused across queries)', () => {
|
||||
const surface = plantSurface('surface', '<p>alpha beta alpha</p>')
|
||||
performScopedFind(surface, 'alpha', { forward: true, findNext: false })
|
||||
|
||||
@@ -320,10 +320,17 @@ export function performScopedFind(
|
||||
}
|
||||
|
||||
const existingMarks = [...root.querySelectorAll<HTMLElement>(`mark.${HIGHLIGHT_CLASS}`)]
|
||||
// The marks store the ORIGINAL-CASE source slice (`highlightMatches`
|
||||
// writes `mark.textContent = matchText`), so byte-equality against the
|
||||
// typed query fails on the first match whose casing differs — 'Hermes'
|
||||
// for 'hermes', sentence-initial capitals, ALL-CAPS. Without the
|
||||
// case-insensitive comparison, every Enter/⌘G step re-wraps all
|
||||
// highlights, `data-find-active` is lost on the fresh DOM, and the
|
||||
// active ordinal resets to 1 forever (triage finding on #81778).
|
||||
const sameQuery =
|
||||
options.findNext &&
|
||||
existingMarks.length > 0 &&
|
||||
existingMarks.every(mark => mark.textContent === query)
|
||||
existingMarks.every(mark => mark.textContent.toLowerCase() === query.toLowerCase())
|
||||
|
||||
let marks = existingMarks
|
||||
|
||||
|
||||
Reference in New Issue
Block a user