Search: mark matches whose raw text contains internal punctuation (#260)#261
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #260.
searchPhrase()compares punctuation-stripped text on both sides, buthighlightSubstring()looked the stripped needle up in the raw span text with a plainindexOf. A query likespeaker-2therefore matched[SPEAKER-2]— the span gained thesearch-matchclass — 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, andhighlightSubstring()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:
__TEST__/hyperaudio-lite-extension.test.js(13 tests, jsdom) coveringfindRawRange,searchPhrase(plain words,[SPEAKER-2],well-known,U.S., multi-word phrases, re-search clearing) andclearPreviousSearch. The extension gets the same CommonJS export guardcaption.jsuses for its tests.U.S.the mark coversU.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.