Repository navigation
Highlight the right characters when folding changes the length - #14
Merged
Merged
Conversation
highlightMatchingTokenizedPrefixes searched a folded copy of the string and applied the found range to the original. Folding changes the length of characters like "é" or full-width letters, so with "Café Olé" and the search "ole" it highlighted " Ol" instead of "Olé". It now searches the original string with the folding as comparison options, passes the locale on to the tokenization, and drops the @available attribute that only repeated the package's minimum versions.
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.
Overview
highlightMatchingTokenizedPrefixes(in:locale:)searched a folded copy of the text (diacritics, case and width removed) and applied the found ranges to the original string. Folding changes the length of characters like "é", "ü" or full-width letters, so the highlight slid sideways. It now searches the original string with the folding as comparison options, skips empty tokens, and passeslocaleon to the tokenization. The@availablethat only repeated the package minimum is gone.Old vs. new, side by side:
mainhighlightsoleallesworgenbudgetIdentical results for ASCII, case differences, "ß", half-width kana, CJK, emoji, an empty search, double spaces and Turkish with
locale: tr. No case was found in which the new code is worse.Out of scope: both versions highlight only the first occurrence per token, even in the middle of a word ("lock" in "unlock"). That is a separate change.
Split out of #7.
How this was verified
StringExtTestscovers plain matches and the folding cases above as a parameterized test.Red, with
main'sStringExt.swift:Green, this branch: