GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(shared): highlight dotted capital I matches in message search (#4… · patroza/t3code@23057dd

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/shared/src
    • paletteSearch.test.ts
    • paletteSearch.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/shared/src/paletteSearch.test.ts‎

Copy file name to clipboardExpand all lines: packages/shared/src/paletteSearch.test.ts
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,34 @@ describe("findSearchTokenRanges", () => {
753753
{ start: 15, end: 20 },
754754
]);
755755
});
756+
757+
it("highlights a dotted capital I as the message matches it", () => {
758+
const text = "İ, then İstanbul guide";
759+
expect(findSearchTokenRanges(text, "İstanbul")).toEqual([{ start: 8, end: 16 }]);
760+
expect(findSearchTokenRanges(text, "İSTANBUL guide")).toEqual([
761+
{ start: 8, end: 16 },
762+
{ start: 17, end: 22 },
763+
]);
764+
expect(findSearchTokenRanges(text, '"İstanbul guide"')).toEqual([{ start: 8, end: 22 }]);
765+
// Other marks stay: a short word keeps its vowel sign rather than lighting up a lone consonant.
766+
expect(findSearchTokenRanges("दिल्ली में मौसम मेरा", "में")).toEqual([{ start: 7, end: 10 }]);
767+
// Touching exact matches stay apart; an overlap does not hide the next match.
768+
expect(findSearchTokenRanges("Foo BarFoo Bar", '"foo bar"')).toEqual([
769+
{ start: 0, end: 7 },
770+
{ start: 7, end: 14 },
771+
]);
772+
expect(findSearchTokenRanges("i i\u0307 i i", '"İ i"')).toEqual([
773+
{ start: 0, end: 3 },
774+
{ start: 5, end: 8 },
775+
]);
776+
// Token order does not matter.
777+
for (const query of ["ist İst", "İst ist"]) {
778+
expect(findSearchTokenRanges("list and İst", query)).toEqual([
779+
{ start: 1, end: 4 },
780+
{ start: 9, end: 12 },
781+
]);
782+
}
783+
});
756784
});
757785

758786
describe("scoreMessageMatch", () => {
Collapse file

‎packages/shared/src/paletteSearch.ts‎

Copy file name to clipboardExpand all lines: packages/shared/src/paletteSearch.ts
+36-22Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const UPPERCASE = /\p{Lu}/u;
1010
const DIGIT = /\p{N}/u;
1111
const LETTER = /\p{L}/u;
1212
const COMBINING_MARKS = /\p{M}/gu;
13+
const DOT_FROM_LOWERCASED_I = /(?<=i)\u0307/g;
1314
// Emoji and other symbols can be searched for, so they start words too.
1415
const SYMBOL = /\p{So}/u;
1516
const APOSTROPHE = /['’]/;
@@ -832,34 +833,47 @@ function shortestSpan(places: ReadonlyArray<ReadonlyArray<number>>): {
832833
*/
833834
export function findSearchTokenRanges(text: string, query: string): SearchRange[] {
834835
const { long, words, exact } = messageSearchTokens(query);
836+
// Each word also without the dot lowercasing "İ" adds, which the text,
837+
// folded in place, does not have. Other marks stay: dropping a Hindi vowel
838+
// sign would leave a lone consonant lighting up word starts.
839+
const undotted = (word: string) => word.replace(DOT_FROM_LOWERCASED_I, "");
835840
// An exact query lights up only where its words are written together.
836-
const phrase = exact
837-
? wordsTogether(
838-
words.map((word) => foldInPlace(word)),
839-
true,
840-
)
841-
: null;
842-
if (phrase) {
841+
if (exact && words.length > 1) {
842+
const folded = words.map((word) => foldInPlace(word));
843+
const bare = folded.map(undotted);
843844
const searched = foldInPlace(text);
844845
const ranges: SearchRange[] = [];
845-
for (
846-
let found = findExactPhrase(text, searched, phrase);
847-
found !== null;
848-
found = findExactPhrase(text, searched, phrase, found.end)
849-
) {
850-
ranges.push(found);
846+
for (const phraseWords of bare.join(" ") === folded.join(" ") ? [folded] : [folded, bare]) {
847+
const phrase = wordsTogether(phraseWords, true)!;
848+
for (
849+
let found = findExactPhrase(text, searched, phrase);
850+
found !== null;
851+
found = findExactPhrase(text, searched, phrase, found.end)
852+
) {
853+
ranges.push(found);
854+
}
851855
}
852-
return ranges;
856+
// Overlaps go, longest first; touching matches stay apart, so find opens
857+
// on the first one alone.
858+
const kept: SearchRange[] = [];
859+
for (const range of ranges.sort(
860+
(left, right) => left.start - right.start || right.end - left.end,
861+
)) {
862+
if (range.start >= (kept.at(-1)?.end ?? 0)) kept.push(range);
863+
}
864+
return kept;
853865
}
854-
const tokens = new Map(
855-
long
856-
.map(
857-
(token) =>
858-
[foldQueryWords(token), Array.from(token).length < MESSAGE_WORD_START_LENGTH] as const,
859-
)
866+
// Each folded token, and whether it must start a word; a spelling any token
867+
// allows mid-word lights up mid-word.
868+
const tokens = new Map<string, boolean>();
869+
for (const token of long) {
870+
const short = Array.from(token).length < MESSAGE_WORD_START_LENGTH;
871+
const word = foldQueryWords(token);
872+
for (const key of [word, undotted(word)]) {
860873
// Some tokens fold to nothing ("´´´"), which would match everywhere.
861-
.filter(([token]) => token.length > 0),
862-
);
874+
if (key.length > 0) tokens.set(key, short && (tokens.get(key) ?? true));
875+
}
876+
}
863877
if (tokens.size === 0) return [];
864878
const field = foldSearchField(text);
865879
const ranges: SearchRange[] = [];

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.