The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 14:45 UTC
fix(web): PDF find matches curly quotes when you type straight ones (#29802)
Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Alex Southwell committed
Nov 15, 2026 at 02:24 UTC
8b633d9a9e54d9e580f6e77540a04bb87cf2da78
2 files changed
+22
-5
apps/web/src/components/files/pdfLayout.test.ts
+13
@@ -147,6 +147,19 @@ describe("pdfFindMatchRuns", () => {
147
expect(pdfFindIncludes(page, " ")).toBe(false);
148
});
149
150
+ it("matches straight quotes typed for typeset curly ones", () => {
151
+ expect(pdfFindMatchRuns(["We don\u2019t ", "ship \u201cbeta\u201d"], "don't")).toEqual([
152
+ true,
153
+ false,
154
+ ]);
155
+ expect(pdfFindMatchRuns(["We don\u2019t ", "ship \u201cbeta\u201d"], '"beta"')).toEqual([
156
+ false,
157
+ true,
158
+ ]);
159
+ expect(pdfFindIncludes("We don\u2019t ship \u201cbeta\u201d", 'don\'t ship "beta"')).toBe(true);
160
+ expect(pdfFindIncludes("We don't ship", "don\u2019t")).toBe(true);
161
+ });
162
+
163
it("highlights nothing for a blank or missing query", () => {
164
expect(pdfFindMatchRuns(["a b", "c"], " ")).toEqual([false, false]);
165
expect(pdfFindMatchRuns(["a b", "c"], "")).toEqual([false, false]);
apps/web/src/components/files/pdfLayout.ts
+9
-5
@@ -72,6 +72,11 @@ export function pdfPageText(
72
return items.map((item) => ("str" in item ? item.str + (item.hasEOL ? "\n" : "") : "")).join("");
73
}
74
75
+// A typed straight quote finds a typeset curly one, as pdf.js's own find does.
76
+function foldQuotes(text: string) {
77
+ return text.replace(/[\u2018-\u201b]/g, "'").replace(/[\u201c-\u201f]/g, '"');
78
+}
79
+
80
/**
81
* Lowercased search text with each whitespace run, line ends included, read as one space, and a
82
* hyphen that ends a line between letters dropped, as pdf.js's own find does. `owner` maps each
@@ -79,7 +84,7 @@ export function pdfPageText(
84
*/
85
function pdfFindText(runs: readonly string[]) {
86
const chars = runs.flatMap((run, index) =>
82
- Array.from(run.toLowerCase(), (char) => ({ char, run: index })),
87
+ Array.from(foldQuotes(run.toLowerCase()), (char) => ({ char, run: index })),
88
);
89
let text = "";
90
let last = "";
@@ -111,10 +116,9 @@ function pdfFindText(runs: readonly string[]) {
116
/** Whether a page's text holds the query, under the same rules as `pdfFindMatchRuns`, without
117
* mapping characters back to runs: the page scan checks every page on each query. */
118
export function pdfFindIncludes(text: string, query: string) {
114
- const needle = query.toLowerCase().replace(/\s+/g, " ");
119
+ const needle = foldQuotes(query.toLowerCase()).replace(/\s+/g, " ");
120
if (!needle.trim()) return false;
116
- return text
117
- .toLowerCase()
121
+ return foldQuotes(text.toLowerCase())
122
.replace(/(\p{L})-\n(?=\p{L})/gu, "$1")
123
.replace(/\s+/g, " ")
124
.includes(needle);
@@ -123,7 +127,7 @@ export function pdfFindIncludes(text: string, query: string) {
127
/** Which text runs hold part of a case-insensitive match, when pdf.js splits words across spans. */
128
export function pdfFindMatchRuns(runs: readonly string[], query: string) {
129
const { text, owner } = pdfFindText(runs);
126
- const needle = query.toLowerCase().replace(/\s+/g, " ");
130
+ const needle = foldQuotes(query.toLowerCase()).replace(/\s+/g, " ");
131
const hits = runs.map(() => false);
132
if (!needle.trim()) return hits;
133
for (