From af9a63e46209e69f8910ee8009c69ce684444861 Mon Sep 17 00:00:00 2001 From: ANIRUDDHA ADAK Date: Mon, 14 Sep 2026 08:25:34 +0530 Subject: [PATCH] fix(print-range): accept em-dash, tilde and fullwidth dash variants (#356) * fix(print-range): accept em-dash, tilde and fullwidth dash variants * fix(sheets): satisfy exactOptionalPropertyTypes for LazyCellMatch rawValue --------- Co-authored-by: Aniruddha Adak --- apps/docs/src/renderer/print-range.ts | 9 +++++---- apps/docs/tests/print-range.test.ts | 8 ++++++++ apps/slides/src/shared/print-html.ts | 4 ++-- apps/slides/tests/print-html.test.ts | 13 +++++++++++++ 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/apps/docs/src/renderer/print-range.ts b/apps/docs/src/renderer/print-range.ts index f9e8582..4e503d2 100644 --- a/apps/docs/src/renderer/print-range.ts +++ b/apps/docs/src/renderer/print-range.ts @@ -1,16 +1,17 @@ /** * Parse a Word-style print range ("1,3,5-8") into sorted 0-based page indices. - * Accepts CJK/ASCII separators and en-dashes; returns null on any invalid or - * out-of-bounds part (same semantics as the slides print dialog). + * Accepts CJK/ASCII separators and dashes: hyphen, en-dash, em-dash, tilde, + * fullwidth tilde and wave dash (Word IME users often type ~/〜 instead of -); + * returns null on any invalid or out-of-bounds part (same semantics as the slides print dialog). */ export function parsePrintRange(text: string, max: number): number[] | null { const out = new Set() - const tokenRe = /\d+\s*[-–]\s*\d+|\d+/g + const tokenRe = /\d+\s*[-–—~~〜]\s*\d+|\d+/g const parts = text.match(tokenRe) ?? [] if (parts.length === 0) return null if (text.replace(tokenRe, '').replace(/[,,、;;\s]/g, '') !== '') return null for (const part of parts) { - const m = /^(\d+)\s*[-–]\s*(\d+)$|^(\d+)$/.exec(part) + const m = /^(\d+)\s*[-–—~~〜]\s*(\d+)$|^(\d+)$/.exec(part) if (!m) return null const a = Number(m[1] ?? m[3]) const b = Number(m[2] ?? m[3]) diff --git a/apps/docs/tests/print-range.test.ts b/apps/docs/tests/print-range.test.ts index 8c5edb2..dd31cb4 100644 --- a/apps/docs/tests/print-range.test.ts +++ b/apps/docs/tests/print-range.test.ts @@ -19,6 +19,14 @@ describe('parsePrintRange', () => { expect(parsePrintRange('1 – 3, 5', 5)).toEqual([0, 1, 2, 4]) }) + it('accepts em-dash, tilde, fullwidth tilde and wave dash (IME variants)', () => { + expect(parsePrintRange('1—3', 5)).toEqual([0, 1, 2]) + expect(parsePrintRange('1~3', 5)).toEqual([0, 1, 2]) + expect(parsePrintRange('1~3', 5)).toEqual([0, 1, 2]) + expect(parsePrintRange('1〜3', 5)).toEqual([0, 1, 2]) + expect(parsePrintRange('1 — 3, 5~6', 6)).toEqual([0, 1, 2, 4, 5]) + }) + it('rejects empty, malformed, reversed, and out-of-bounds input', () => { expect(parsePrintRange('', 5)).toBeNull() expect(parsePrintRange('a-b', 5)).toBeNull() diff --git a/apps/slides/src/shared/print-html.ts b/apps/slides/src/shared/print-html.ts index a7d756d..265df4c 100644 --- a/apps/slides/src/shared/print-html.ts +++ b/apps/slides/src/shared/print-html.ts @@ -26,12 +26,12 @@ export interface PrintDocOptions { /** "1,3,5-8" → 0-based slide indices (1-based input over the whole deck); null = invalid */ export function parsePrintRange(text: string, max: number): number[] | null { const out = new Set() - const tokenRe = /\d+\s*[-–]\s*\d+|\d+/g + const tokenRe = /\d+\s*[-–—~~〜]\s*\d+|\d+/g const parts = text.match(tokenRe) ?? [] if (parts.length === 0) return null if (text.replace(tokenRe, '').replace(/[,,、;;\s]/g, '') !== '') return null for (const part of parts) { - const m = /^(\d+)\s*[-–]\s*(\d+)$|^(\d+)$/.exec(part) + const m = /^(\d+)\s*[-–—~~〜]\s*(\d+)$|^(\d+)$/.exec(part) if (!m) return null const a = Number(m[1] ?? m[3]) const b = Number(m[2] ?? m[3]) diff --git a/apps/slides/tests/print-html.test.ts b/apps/slides/tests/print-html.test.ts index d33b610..006fe02 100644 --- a/apps/slides/tests/print-html.test.ts +++ b/apps/slides/tests/print-html.test.ts @@ -27,6 +27,19 @@ describe('parsePrintRange', () => { expect(parsePrintRange('1 - 3', 5)).toEqual([0, 1, 2]) expect(parsePrintRange('1 – 3, 5', 5)).toEqual([0, 1, 2, 4]) }) + + it('accepts em-dash, tilde, fullwidth tilde and wave dash (IME variants)', () => { + expect(parsePrintRange('1—3', 5)).toEqual([0, 1, 2]) + expect(parsePrintRange('1~3', 5)).toEqual([0, 1, 2]) + expect(parsePrintRange('1~3', 5)).toEqual([0, 1, 2]) + expect(parsePrintRange('1〜3', 5)).toEqual([0, 1, 2]) + expect(parsePrintRange('1 — 3, 5~6', 6)).toEqual([0, 1, 2, 4, 5]) + }) + + it('accepts spaces around dashes', () => { + expect(parsePrintRange('1 - 3', 5)).toEqual([0, 1, 2]) + expect(parsePrintRange('1 – 3, 5', 5)).toEqual([0, 1, 2, 4]) + }) }) describe('printPageCount', () => {