From 10dfe102ecd999421978c025e8deb57d3bfdf122 Mon Sep 17 00:00:00 2001 From: Connor Burgess Date: Thu, 3 Dec 2026 10:50:28 +0700 Subject: [PATCH 1/2] =?UTF-8?q?palette:=20a=20title=20with=20a=20dotted=20?= =?UTF-8?q?capital=20=C4=B0=20no=20longer=20throws=20or=20shifts=20its=20u?= =?UTF-8?q?nderlines?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Symptom: typing in the command palette when a session title, machine, branch or file name holds "İ" (U+0130) underlined the wrong characters ("pay" in "İstanbul payments" underlined "aym"), and a match on the last character threw "Cannot read properties of undefined (reading 'toLowerCase')" during render, taking the page down. Cause: fuzzy() lowered the query and the text with toLowerCase() and used indexes into the lowered string against the original text. "İ" lowercases to "i" plus a combining dot, two UTF-16 units where the text has one, so every index after it ran one past the text, up to text.length. Fix: lower both strings with every İ first replaced by a plain "i", so they keep their length and an index into the lowered text is an index into the text. A string without an İ is lowered exactly as before. Signed-off-by: Connor Burgess --- web/src/lib/fuzzy.test.ts | 57 +++++++++++++++++++++++++++++++++++++++ web/src/lib/fuzzy.ts | 10 +++++-- 2 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 web/src/lib/fuzzy.test.ts diff --git a/web/src/lib/fuzzy.test.ts b/web/src/lib/fuzzy.test.ts new file mode 100644 index 00000000..df8a7642 --- /dev/null +++ b/web/src/lib/fuzzy.test.ts @@ -0,0 +1,57 @@ +// SPDX-License-Identifier: Apache-2.0 +import { describe, expect, it } from "vitest"; +import { fuzzy, fuzzyFields } from "./fuzzy"; + +/** The characters a match underlines. */ +const underlined = (text: string, positions: number[]) => positions.map((p) => text[p]).join(""); + +describe("fuzzy", () => { + it("matches a subsequence case-insensitively and underlines it", () => { + const m = fuzzy("pay", "Payments"); + expect(m?.positions).toEqual([0, 1, 2]); + expect(fuzzy("xyz", "Payments")).toBeNull(); + expect(fuzzy("", "Payments")).toEqual({ score: 0, positions: [] }); + }); + + // "İ" (U+0130) lowercases to "i" and a combining dot, two UTF-16 units where the text has + // one, so indexes into the lowered text ran one past the text's own characters. + it("underlines the right characters after a dotted capital İ", () => { + const text = "İstanbul payments"; + const m = fuzzy("pay", text); + expect(m?.positions).toEqual([9, 10, 11]); + expect(underlined(text, m?.positions ?? [])).toBe("pay"); + expect(fuzzy("x", "İX")?.positions).toEqual([1]); + }); + + it("does not throw on a match at the end of a text with a dotted capital İ", () => { + expect(fuzzy("s", "İstanbul payments")?.positions).toEqual([1]); + expect(fuzzy("ts", "İstanbul payments")?.positions).toEqual([15, 16]); + }); + + it("matches a dotted capital İ as an i, in the text and in the query", () => { + expect(fuzzy("ist", "İstanbul")?.positions).toEqual([0, 1, 2]); + expect(fuzzy("İst", "istanbul")?.positions).toEqual([0, 1, 2]); + expect(fuzzy("İst", "İstanbul")?.positions).toEqual([0, 1, 2]); + }); + + it("still lowers a word-final sigma in a text with a dotted capital İ", () => { + const text = "İzmir ΟΔΟΣ"; + expect(fuzzy("οδος", text)?.positions).toEqual([6, 7, 8, 9]); + expect(fuzzy("ΟΔΟΣ", text)?.positions).toEqual([6, 7, 8, 9]); + }); + + it("keeps lower-casing text without an İ as it was", () => { + expect(fuzzy("k", "K")?.positions).toEqual([0]); // the Kelvin sign + expect(fuzzy("οδος", "ΟΔΟΣ")?.positions).toEqual([0, 1, 2, 3]); // the final sigma + expect(fuzzy("ss", "straße")).toBeNull(); // no case folding + }); +}); + +describe("fuzzyFields", () => { + it("does not throw on a field with a dotted capital İ and underlines the right characters", () => { + const fields = ["Claude", "İzmir deployments"]; + const m = fuzzyFields("ments", fields); + expect(m?.positions[0]).toEqual([]); + expect(underlined(fields[1] as string, m?.positions[1] ?? [])).toBe("ments"); + }); +}); diff --git a/web/src/lib/fuzzy.ts b/web/src/lib/fuzzy.ts index 9913bcb7..3811fc7d 100644 --- a/web/src/lib/fuzzy.ts +++ b/web/src/lib/fuzzy.ts @@ -23,6 +23,12 @@ const BOUNDARY = /[\s\-_./:@#()[\]{}"'“”«»,;|]/; const isUpper = (c: string) => c !== c.toLowerCase() && c === c.toUpperCase(); const isLower = (c: string) => c !== c.toUpperCase() && c === c.toLowerCase(); +/** `s` in lower case and the same length, so an index into it is an index into `s`. The + * dotted capital İ (U+0130) is the one character whose lower case is longer: "i" and a + * combining dot, which would shift every index after it. It lowers to the "i" alone here; + * everything else, a word-final sigma included, lowers as the whole string does. */ +const lowerSameLength = (s: string) => s.replace(/\u0130/g, "i").toLowerCase(); + /** Whether `text[i]` begins a word. */ export function isWordStart(text: string, i: number): boolean { if (i <= 0) return true; @@ -35,8 +41,8 @@ export function isWordStart(text: string, i: number): boolean { /** The best way `query` fits into `text` as a subsequence, or null when it does not. * An empty query matches everything with a score of 0. */ export function fuzzy(query: string, text: string): FuzzyMatch | null { - const q = query.toLowerCase(); - const t = text.toLowerCase(); + const q = lowerSameLength(query); + const t = lowerSameLength(text); const m = q.length; const n = t.length; if (m === 0) return { score: 0, positions: [] }; From 2b43327d1ba0822937971760b01f61b1827c403e Mon Sep 17 00:00:00 2001 From: Connor Burgess Date: Sat, 5 Dec 2026 07:19:27 +0700 Subject: [PATCH 2/2] docs: record the fix under Unreleased Signed-off-by: Connor Burgess --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5299e266..33411c5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ All notable changes to `sessionpipe-gui`. The format follows ## [Unreleased] +### Fixed + +- Command palette matches containing a dotted capital İ keep the correct underline positions without throwing. + ## [0.8.18] - 2026-12-04 ### Fixed