Bento, the office suite that fits in a file
TypeScript mit-licenseofficeoffice-365office-suiteoffice-toolsoffice365open-sourcepowerpointself-hostedsingle-page-appslidesslideshareslideshowslideshow-galleryslideshow-makerslideshows
slides: a typed bullet keeps its space (#501) (#505)
nyblnet83318c08e773
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a6f1e9b4..8c3a75f2 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -11,6 +11,11 @@ pre-1.0.## [Unreleased]+- **A typed bullet keeps its space.** Typing `- ` made the bullet, but the+ next letter landed right against it — the space after the glyph was a+ plain space at the end of the line, which the browser treats as nothing and+ the next keystroke replaced. It is a non-breaking space now, for top-level+ and indented bullets alike, typed or pasted. Reported by Hermholtz (#501).- **Pasting into a table cell lands once.** Edit a cell, leave it unchanged,edit it again — each visit quietly added another set of keystroke and pastehandlers to the same cell, so a later paste landed once per visit (fourdiff --git a/scripts/test-slides-compact-layouts.ts b/scripts/test-slides-compact-layouts.tsindex 69383829..0d6ed38f 100644--- a/scripts/test-slides-compact-layouts.ts+++ b/scripts/test-slides-compact-layouts.ts@@ -72,7 +72,7 @@ const a = one.doc.slides[0], b = one.doc.slides[1]const ref = findLayout('title-body', { size: { width: 1280, height: 720 } })!ok(els(a).map((e) => e.id).join() === ref.elements.map((e) => e.id).join(), 'the slide has exactly the layout\'s elements, in order, with the layout\'s ids')ok(frame(text(a, 'ltc-title')) === frame(text(ref, 'ltc-title')) && frame(text(a, 'ltc-body')) === frame(text(ref, 'ltc-body')), 'title and body sit exactly on the layout\'s frames')-ok(text(a, 'ltc-title')!.html === 'Hi' && /• a<br>• b|<li>a/.test(text(a, 'ltc-body')!.html), 'content applied: the title, and the markdown body as the editor converts it')+ok(text(a, 'ltc-title')!.html === 'Hi' && /•\u00a0a<br>•\u00a0b|<li>a/.test(text(a, 'ltc-body')!.html), 'content applied: the title, and the markdown body as the editor converts it')ok(text(a, 'ltc-title')!.fontSize === text(ref, 'ltc-title')!.fontSize && text(a, 'ltc-title')!.fontWeight === 700, 'typography is the layout\'s (44→scaled, weight 700), not the compact default')ok(els(a).every((e) => !(e.placeholder && !(e.html as string))), 'no leftover placeholder prompt: every text slot was filled')ok(text(b, 'ltc-title')!.id === text(a, 'ltc-title')!.id, 'two slides from the same layout share element ids — their titles morph')diff --git a/scripts/test-slides-links.ts b/scripts/test-slides-links.tsindex 11ac3438..f1e3c723 100644--- a/scripts/test-slides-links.ts+++ b/scripts/test-slides-links.ts@@ -39,10 +39,20 @@ ok(!isWebUrl('https://' + 'a'.repeat(2100)), 'length is bounded')ok(!isWebUrl(42) && !isWebUrl(null), 'non-strings are not links')console.log('\nmarkdownToHtml — bullets\n')-ok(markdownToHtml('- one\n- two') === '• one<br>• two', '"- " makes a bullet')-ok(markdownToHtml('* one\n* two') === '• one<br>• two', '"* " makes a bullet too (#255)')-ok(markdownToHtml('- top\n - sub\n * subsub') === '• top<br> ◦ sub<br> ◦ subsub',+// The glyph is followed by an NBSP (U+00A0), never a plain space: at the end+// of a text node a plain space is a collapsed trailing space that the next+// typed character replaces — "- " then "x" gave "•x" (discussion #501).+const NB = '\u00a0'+ok(markdownToHtml('- one\n- two') === `•${NB}one<br>•${NB}two`, '"- " makes a bullet, glyph + NBSP')+ok(markdownToHtml('* one\n* two') === `•${NB}one<br>•${NB}two`, '"* " makes a bullet too (#255)')+ok(markdownToHtml('- top\n - sub\n * subsub') === `•${NB}top<br>${NB}${NB}◦${NB}sub<br>${NB}${NB}${NB}${NB}◦${NB}subsub`,'two or more leading spaces make an indented sub-bullet, indent kept as NBSPs (#368)')+{+ const src = readFileSync(new URL('../slides/src/editor/markdown.ts', import.meta.url), 'utf8')+ const typed = /bullet\[1\] \? '◦(.)' : '•(.)'/.exec(src)+ ok(!!typed && typed[1] === NB && typed[2] === NB, 'typing "- " inserts the glyph + NBSP too (the autoformat literal, #501)')+ ok(!/[•◦] '/.test(src.replace(/\/\/[^\n]*/g, '')), 'no glyph is followed by a plain space anywhere in the converter')+}ok(markdownToHtml('\\- not a bullet') === '- not a bullet' && markdownToHtml('\\* not a bullet') === '* not a bullet', 'escaped markers stay literal')ok(markdownToHtml('2 * 3 = 6') === '2 * 3 = 6', 'a * mid-line is arithmetic, not a bullet')ok(markdownToHtml('*em*') === '<i>em</i>', '*italic* still works — a bullet needs the trailing space at line start')diff --git a/slides/src/editor/markdown.ts b/slides/src/editor/markdown.tsindex 131a6676..8690662e 100644--- a/slides/src/editor/markdown.ts+++ b/slides/src/editor/markdown.ts@@ -67,13 +67,15 @@ export function autoformatAtCaret(): boolean {const upto = node.data.slice(0, off)// "- " or "* " at line start → bullet glyph (contentEditable renders the- // trailing space as NBSP, so match both; keep NBSP so the glyph's gap can't- // collapse). Indented by two or more spaces → a hollow sub-bullet, the+ // trailing space as NBSP, so match both). The glyph is followed by an NBSP:+ // a plain space at the end of a text node is a collapsed trailing space that+ // the next typed character simply replaces — "•x", no gap (discussion+ // #501; measured: "- " then "x" gave U+2022 U+0078). Indented by two or more spaces → a hollow sub-bullet, the// indent kept (discussions #255, #368).const bullet = upto.match(/(?:^|\n)([ ]{2,})?[-*][ ]$/)if (bullet && off >= 2 && isLineStart(node, off - 2 - (bullet[1]?.length ?? 0))) {const source = node.data.slice(off - 2, off)- node.replaceData(off - 2, 2, bullet[1] ? '◦ ' : '• ')+ node.replaceData(off - 2, 2, bullet[1] ? '◦ ' : '• ')placeCaret(node, off)lastFormat = { kind: 'bullet', node, offset: off - 2, source }return true@@ -160,8 +162,8 @@ export function markdownToHtml(text: string): string {.map((line) => {// "- " / "* " → bullet; indented two+ spaces → sub-bullet, indent kept as// NBSPs so it survives HTML whitespace collapsing- let s = escapeHtml(line).replace(/^( {2,})[-*] /, (_, sp: string) => '\u00a0'.repeat(sp.length) + '◦ ')- .replace(/^( ?)[-*] /, '$1• ')+ let s = escapeHtml(line).replace(/^( {2,})[-*] /, (_, sp: string) => '\u00a0'.repeat(sp.length) + '◦ ')+ .replace(/^( ?)[-*] /, '$1• ')s = s.replace(/\[([^\[\]]+)\]\((https?:\/\/[^\s()]+)\)/gi, (m, cap: string, href: string) =>isWebUrl(href) ? `<a href="${href.replaceAll('"', '"')}">${cap}</a>` : m)s = s.replace(/\*\*([^*]+)\*\*/g, '<b>$1</b>')