fix(cli): count a contraction as one word in line_unread (#6346)

WORD_RUNS split at apostrophes, so "can't" counted as two words and a line with contractions got a longer hold floor than its real word count.

Refs #6338
This commit is contained in:
berce
2026-10-25 23:28:11 +00:00
committed by GitHub
parent 3c016f6280
commit 8a6340f633
2 changed files with 7 additions and 1 deletions
@@ -81,6 +81,12 @@ describe("readingWords", () => {
expect(readingWords("✓ — →")).toBe(0);
expect(readingWords("今天天气很好")).toBeGreaterThan(1);
});
it("counts a contraction as one word", () => {
expect(readingWords("a tooth can't get in")).toBe(5);
expect(readingWords("a tooth can’t get in")).toBe(5);
expect(readingWords("it's 'quoted'")).toBe(2);
});
});
describe("lineFloorSec", () => {
+1 -1
View File
@@ -29,7 +29,7 @@ const CRAFT_THRESHOLDS = {
const T = CRAFT_THRESHOLDS;
const ZERO_BBOX: CheckBbox = { x: 0, y: 0, width: 0, height: 0 };
const WORD_RUNS = /[\p{L}\p{M}\p{N}%$]+/gu;
const WORD_RUNS = /[\p{L}\p{M}\p{N}%$]+(?:['’][\p{L}\p{M}\p{N}]+)*/gu;
// Chinese and Japanese have no spaces; a dictionary segmenter counts their words like an English line's.
const WORD_SEGMENTER = new Intl.Segmenter("ja", { granularity: "word" });