Bento, the office suite that fits in a file
TypeScript mit-licenseofficeoffice-365office-suiteoffice-toolsoffice365open-sourcepowerpointself-hostedsingle-page-appslidesslideshareslideshowslideshow-galleryslideshow-makerslideshows
slides: typing after an inline code run that ends a line is plain text (#626) (#694)
nyblnetc7660a610715
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 4277677c..c8a37cda 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -2394,6 +2394,11 @@ jobs:# restores; paste moves it to the pointer in one undo step, across# slides, without two elements sharing an id on one slide.run: node scripts/test-slides-ghost-cut-browser.mjs+ - name: Leaving an inline code run in Chromium+ # A text box that already ends a line in `code` (reopened, pasted):+ # typing at the end of that line is plain text, at the box's end or+ # before a line break; opening and closing a box changes nothing.+ run: node scripts/test-slides-code-run-exit-browser.mjs- name: Connectors route on every slide in Chromium# #493: a deck saved or loaded with stale connector endpoints opens with# every slide's connectors on their elements' borders (thumbnail too),diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 98c00204..9d4d37bb 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -11,6 +11,11 @@ pre-1.0.## [Unreleased]+- **Typing after inline code at the end of a line is plain text again.** In a+ text box that already ended a line with `code` — one you saved and reopened,+ or pasted — the caret could only sit inside the code, so everything typed at+ the end of that line became code too, and no key got you out. Reported in+ discussion #626.- **Connectors in decks written outside the editor now attach.** A deck madeby hand or by an AI agent can name the two elements a connector joinswithout giving it the right endpoints. Until now only the slide on screen wasdiff --git a/scripts/test-slides-code-run-exit-browser.mjs b/scripts/test-slides-code-run-exit-browser.mjsnew file mode 100644index 00000000..29967627--- /dev/null+++ b/scripts/test-slides-code-run-exit-browser.mjs@@ -0,0 +1,87 @@+// SPDX-License-Identifier: MIT+// Copyright (c) 2026 The Bento authors+// Typing after an inline code run that ends a line types plain text (#626).+//+// npm run build:single --prefix slides && node scripts/test-slides-code-run-exit-browser.mjs+//+// WHAT THIS PROVES, with real mouse and keyboard in the packaged editor. A+// text box that ALREADY ends in a `code` run — saved, reopened, pasted, from a+// file — had no text position after the <code>, so the caret could only sit+// inside it: everything typed at the end of the line became code, and no+// arrow key got out. (The ` autoformat leaves a zero-width space after the+// code it makes, which is why typing it fresh never showed this.) Now a box+// opening for edit gets the same escape hatch after every code run that ends a+// line, and commit strips it:+// 1. click at the end of a line that ends in code, type: the text is plain;+// 2. the same via ⌘↓ + End in the last of two lines;+// 3. a code run that ends the FIRST line (before a <br>) too;+// 4. opening and closing a box without typing leaves its html, and the+// deck, untouched.+const { chromium } = await import(process.env.PLAYWRIGHT_MODULE || 'playwright')++let checks = 0+let failures = 0+function ok(cond, msg) {+ checks+++ if (!cond) { failures++; console.log(` FAIL ${msg}`) } else console.log(` ok ${msg}`)+}+const MOD = process.platform === 'darwin' ? 'Meta' : 'Control'++const browser = await chromium.launch({ executablePath: process.env.CHROME_PATH, headless: true })+try {+ const p = await browser.newPage({ viewport: { width: 1440, height: 1000 } })+ const errors = []+ p.on('pageerror', (e) => errors.push(e.message))+ await p.route(/^https?:/, (r) => r.abort())+ await p.goto(new URL('../slides/dist-single/Bento_Slides.bento.html', import.meta.url).href)+ await p.waitForFunction(() => window.bento?.doc)+ const load = async (html) => {+ await p.evaluate((h) => {+ const d = JSON.parse(JSON.stringify(window.bento.doc))+ d.slides = [{ id: 's1', background: '#ffffff', elements: [+ { id: 't1', type: 'text', x: 100, y: 200, w: 800, h: 200, rotation: 0, opacity: 1, html: h, fontSize: 32, color: '#1e2a3a' },+ ] }]+ window.bento.loadDoc(JSON.stringify(d))+ }, html)+ await p.waitForTimeout(400)+ }+ const html = () => p.evaluate(() => window.bento.doc.slides[0].elements[0].html)+ const box = () => p.locator('.ed-stage-scale [data-el-id="t1"]')+ const edit = async () => { const b = await box().boundingBox(); await p.mouse.dblclick(b.x + 30, b.y + 15); await p.waitForTimeout(250) }+ const leave = async () => { const s = await p.locator('.ed-stage-scale').boundingBox(); await p.mouse.click(s.x + 20, s.y + s.height - 20); await p.waitForTimeout(250) }+ const clickRightOf = async (nth) => {+ const r = await p.evaluate((n) => { const c = document.querySelectorAll('.ed-stage-scale [data-el-id="t1"] code')[n].getBoundingClientRect(); return { x: c.right + 40, y: c.top + c.height / 2 } }, nth)+ await p.mouse.click(r.x, r.y)+ }++ console.log('\nthe end of a line that ends in code\n')+ await load('Hello <code>code</code>')+ await edit(); await clickRightOf(0)+ await p.keyboard.type(' after', { delay: 15 }); await leave()+ ok(await html() === 'Hello <code>code</code> after', `click at the end, type: plain text (${await html()})`)++ await load('First line<br>Hello <code>code</code>')+ await edit(); await p.keyboard.press(`${MOD}+ArrowDown`); await p.keyboard.press('End')+ await p.keyboard.type(' after', { delay: 15 }); await leave()+ ok(await html() === 'First line<br>Hello <code>code</code> after', `⌘↓ + End in the last line: plain text (${await html()})`)++ await load('Hello <code>code</code><br>Second line')+ await edit(); await clickRightOf(0)+ await p.keyboard.type(' after', { delay: 15 }); await leave()+ ok(await html() === 'Hello <code>code</code> after<br>Second line', `a code run ending the FIRST line: plain text (${await html()})`)++ console.log('\nnothing changes unless you type\n')+ for (const h of ['Hello <code>code</code>', 'A <code>mid</code> line<br>End <code>run</code>']) {+ await load(h)+ await p.evaluate(() => { window.__dirtyBefore = document.querySelector('.ed-dirty')?.classList.contains('on') })+ await edit(); await p.keyboard.press('Escape'); await leave()+ const dirty = await p.evaluate(() => document.querySelector('.ed-dirty')?.classList.contains('on'))+ ok(await html() === h && !//.test(await html()), `open and close "${h}": html identical, no zero-width space saved`)+ ok(dirty === (await p.evaluate(() => window.__dirtyBefore)), 'and the deck is no dirtier than before')+ }++ ok(errors.length === 0, `no page errors${errors.length ? ': ' + errors.join('; ') : ''}`)+} finally { await browser.close() }++console.log(`\n${checks - failures}/${checks} checks passed`)+process.exit(failures ? 1 : 0)diff --git a/slides/src/editor/canvas.ts b/slides/src/editor/canvas.tsindex 61205922..8878684e 100644--- a/slides/src/editor/canvas.ts+++ b/slides/src/editor/canvas.ts@@ -1455,6 +1455,17 @@ export class SlideCanvas {inner.innerText = model.contentthis.editingShowedRaw = true}+ // An inline code run that ENDS a line (last thing in the box, or right+ // before a <br>) has no text position after it, so the caret can only sit+ // inside it and everything typed at the end of the line became code (#626).+ // The autoformat leaves a zero-width space after the code it makes; a box+ // opened later (saved, pasted, from a file) gets the same escape hatch+ // here. Commit strips every U+200B, so the saved html is unchanged.+ for (const code of inner.querySelectorAll('code')) {+ const next = code.nextSibling+ if (code.closest('pre') || (next && next.nodeName !== 'BR')) continue+ code.after(document.createTextNode('\u200b'))+ }this.editing = nodethis.editListeners?.abort()this.editListeners = new AbortController()