Skip to content

Search: mark matches whose raw text contains internal punctuation (#260)#261

Merged
maboa merged 1 commit into
mainfrom
260-search-mark-punctuation
Jul 4, 2026
Merged

Search: mark matches whose raw text contains internal punctuation (#260)#261
maboa merged 1 commit into
mainfrom
260-search-mark-punctuation

Conversation

@maboa

@maboa maboa commented Jul 4, 2026

Copy link
Copy Markdown
Member

Fixes #260.

searchPhrase() compares punctuation-stripped text on both sides, but highlightSubstring() looked the stripped needle up in the raw span text with a plain indexOf. A query like speaker-2 therefore matched [SPEAKER-2] — the span gained the search-match class — but the lookup missed on the dash and no <mark class="search-mark"> was ever inserted. Any match containing a stripped character was affected: hyphenated words, dotted abbreviations, bracketed speaker labels.

The fix: a new findRawRange() walks the raw text consuming needle characters and skipping punctuation inside the match, and highlightSubstring() wraps that raw range. The mark now covers the visible word (dash included) while leading/trailing punctuation stays outside, preserving the existing behaviour for plain words.

Also in this PR:

  • New test suite __TEST__/hyperaudio-lite-extension.test.js (13 tests, jsdom) covering findRawRange, searchPhrase (plain words, [SPEAKER-2], well-known, U.S., multi-word phrases, re-search clearing) and clearPreviousSearch. The extension gets the same CommonJS export guard caption.js uses for its tests.
  • Changelog entry under Version 2.6.2 (unreleased) and the extension's version header bumped to 2.6.2 — adjust if the next release number will differ.
  • One behaviour note: for U.S. the mark covers U.S (the final . follows the last needle character, so it stays outside the mark, consistent with the "punctuation stays outside" rule for trailing characters).

All 71 tests pass (npx jest): 58 existing + 13 new.

@maboa
maboa merged commit 43677fb into main Jul 4, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Search: matches containing internal punctuation never get a search-mark (e.g. "speaker-2", "U.S.")

1 participant