Skip to content

Commit d360e14

Browse files
fix(web): a line-end hyphen after an astral letter is dropped in highlights too
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent ad671b6 commit d360e14

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎apps/web/src/components/files/pdfLayout.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ describe("pdfFindMatchRuns", () => {
120120
]);
121121
});
122122

123+
it("drops a line-end hyphen after a letter outside the BMP", () => {
124+
expect(pdfFindMatchRuns(["\u{10400}-", "\n", "\u{10401}"], "\u{10400}\u{10401}")).toEqual([
125+
true,
126+
false,
127+
true,
128+
]);
129+
});
130+
123131
it("finds the same pages the highlights do", () => {
124132
const page = "Q3 quarterly\noutlook ahead, the quar-\nterly report";
125133
expect(pdfFindIncludes(page, "Quarterly OUTLOOK")).toBe(true);

‎apps/web/src/components/files/pdfLayout.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,26 @@ function pdfFindText(runs: readonly string[]) {
6666
Array.from(run.toLowerCase(), (char) => ({ char, run: index })),
6767
);
6868
let text = "";
69+
let last = "";
6970
const owner: number[] = [];
7071
for (let index = 0; index < chars.length; index++) {
7172
const { char, run } = chars[index]!;
7273
if (/\s/.test(char)) {
7374
if (!text.endsWith(" ")) {
7475
text += " ";
76+
last = " ";
7577
owner.push(run);
7678
}
7779
} else if (
7880
char === "-" &&
7981
chars[index + 1]?.char === "\n" &&
80-
/\p{L}/u.test(text.at(-1) ?? "") &&
82+
/\p{L}/u.test(last) &&
8183
/\p{L}/u.test(chars[index + 2]?.char ?? "")
8284
) {
8385
index++;
8486
} else {
8587
text += char;
88+
last = char;
8689
for (let unit = 0; unit < char.length; unit++) owner.push(run);
8790
}
8891
}

0 commit comments

Comments
 (0)