Skip to content

Highlight the right characters when folding changes the length - #14

Merged
Jeehut merged 1 commit into
mainfrom
wip/highlight-folded-ranges
Oct 15, 2026
Merged

Jeehut merged 1 commit into
mainfrom
wip/highlight-folded-ranges

Conversation

@Jeehut

@Jeehut Jeehut commented Oct 14, 2026

Copy link
Copy Markdown
Member

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 passes locale on to the tokenization. The @available that only repeated the package minimum is gone.

Old vs. new, side by side:

Text Search main highlights This branch
Café Olé ole " Ol" "Olé"
Ärger über alles alles "r all" "alles"
Hello World wor "l" "Wor"
Préférences générales gen "s g" "gén"
Meeting mit Jürgen über Budget budget "r Budg" "Budget"

Identical 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

StringExtTests covers plain matches and the folding cases above as a parameterized test.

Red, with main's StringExt.swift:

✘ "Ärger über alles" / "uber"  expected ["über"]
✘ "Hello World" / "wor"     expected ["Wor"]
✘ "Café Olé" / "ole"           expected ["Olé"]
✘ "Ärger über alles" / "alles" expected ["alles"]
✘ Test run with 2 tests in 1 suite failed with 4 issues.

Green, this branch:

✔ Test run with 2 tests in 1 suite passed.

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.
@Jeehut
Jeehut merged commit d26bd15 into main Oct 15, 2026
5 checks passed
@Jeehut
Jeehut deleted the wip/highlight-folded-ranges branch October 15, 2026 09:34
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.

1 participant