Bento, the office suite that fits in a file
TypeScript mit-licenseofficeoffice-365office-suiteoffice-toolsoffice365open-sourcepowerpointself-hostedsingle-page-appslidesslideshareslideshowslideshow-galleryslideshow-makerslideshows
slides: the caret at the start of a line is visible while editing — ring held off the text, idle Moveable box hidden (#547) (#691)
nyblnet942f47f0a493
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 5e4fe4bd..a4e2da49 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -2389,6 +2389,12 @@ 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: Caret at the start of a line in Chromium+ # #547: with the caret at a text box's left edge, nothing paints over+ # it — the editing ring is an outline held off the box, Moveable's+ # leftover lines are hidden for the edit, and a screenshot of the strip+ # beside the caret has no ring-blue in it; the text does not move.+ run: node scripts/test-slides-caret-ring-browser.mjsspaces-save-browser:runs-on: ubuntu-latestdiff --git a/CHANGELOG.md b/CHANGELOG.mdindex 4bf42d7c..dbd1ac9d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -11,6 +11,12 @@ pre-1.0.## [Unreleased]+- **The text cursor shows at the start of a line.** While editing a text+ box, the cursor at the very beginning of a line was hidden under the blue+ editing frame and the selection box's edge. The frame now sits a few pixels+ outside the text, and the selection box steps aside while you type, so the+ cursor is visible wherever it is. The text itself does not move. Reported+ in #547.- **The top bar no longer shifts under your pointer.** Each auto-save's"Saved" note, and the file name beside the deck title appearing ordisappearing, used to push the buttons after them sideways — so when youdiff --git a/scripts/test-slides-caret-ring-browser.mjs b/scripts/test-slides-caret-ring-browser.mjsnew file mode 100644index 00000000..7bb61d0d--- /dev/null+++ b/scripts/test-slides-caret-ring-browser.mjs@@ -0,0 +1,103 @@+// SPDX-License-Identifier: MIT+// Copyright (c) 2026 The Bento authors+// The text caret at the start of a line is visible while editing (#547).+//+// npm run build:single --prefix slides && node scripts/test-slides-caret-ring-browser.mjs+//+// WHAT THIS PROVES, in the packaged editor with real input, light and dark:+// 1. a real double-click enters text editing and ← puts the caret at the+// start of the first line — at the text box's left edge, x = 0;+// 2. nothing paints over that edge: the editing ring is an outline held off+// the box (not a shadow hugging it), Moveable's control box — which keeps+// its last lines drawn although it has no target while you edit — is+// hidden, and a real screenshot of the strip just left of the caret has+// no ring-blue pixel in it (before the fix: the ring and Moveable's left+// line, both blue, sat on that strip);+// 3. the text does not move when editing starts (the model owns geometry);+// 4. once the edit ends and the box is selected again, the control box is+// back — the hide is for the edit only.+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 browser = await chromium.launch({ executablePath: process.env.CHROME_PATH, headless: true })+try {+ for (const theme of ['light', 'dark']) {+ console.log(`\n${theme}\n`)+ const p = await browser.newPage({ viewport: { width: 1440, height: 900 } })+ 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)+ await p.evaluate((th) => {+ document.documentElement.dataset.theme = th+ const d = JSON.parse(JSON.stringify(window.bento.doc))+ d.slides = [{ id: 's1', background: '#ffffff', elements: [{ id: 't1', type: 'text', x: 200, y: 200, w: 600, h: 200, rotation: 0, opacity: 1, html: 'First line<br>Second line', fontSize: 40, color: '#1e2a3a' }] }]+ window.bento.loadDoc(JSON.stringify(d))+ }, theme)+ await p.waitForTimeout(400)+ const textAt = () => p.evaluate(() => {+ const inner = document.querySelector('.ed-stage-scale [data-el-id="t1"] .bento-text-inner')+ const r = document.createRange(); r.selectNodeContents(inner.firstChild); const b = r.getBoundingClientRect()+ return [Math.round(b.left * 100) / 100, Math.round(b.top * 100) / 100]+ })+ const before = await textAt()+ const node = p.locator('.ed-stage-scale [data-el-id="t1"]')+ const nb = await node.boundingBox()+ await p.mouse.dblclick(nb.x + 80, nb.y + 20)+ await p.waitForTimeout(250)+ await p.keyboard.press('ArrowLeft') // collapse the select-all to the very start+ await p.waitForTimeout(250)+ const m = await p.evaluate(() => {+ const inner = document.querySelector('.ed-stage-scale [data-el-id="t1"] .bento-text-inner')+ const sel = getSelection(), rg = sel.getRangeAt(0)+ const r = rg.getClientRects()[0] ?? rg.getBoundingClientRect()+ const ir = inner.getBoundingClientRect(), cs = getComputedStyle(inner)+ const mid = r.top + r.height / 2+ const over = (x) => document.elementsFromPoint(x, mid).filter((e) => e.closest?.('.moveable-control-box')).length+ const box = document.querySelector('.ed-stage-scale .moveable-control-box')+ return {+ editing: inner.isContentEditable && document.activeElement === inner,+ collapsed: rg.collapsed && rg.startOffset === 0,+ caret: [r.left, r.top, r.height], innerLeft: ir.left,+ shadow: cs.boxShadow, outline: cs.outlineStyle, offset: parseFloat(cs.outlineOffset),+ boxVisible: box ? getComputedStyle(box).visibility : 'none',+ overCaret: over(r.left + 0.25) + over(r.left - 0.75),+ }+ })+ ok(m.editing && m.collapsed, 'a real double-click enters editing, and ← puts the caret at the start')+ ok(Math.abs(m.caret[0] - m.innerLeft) < 0.6, `the caret is at the text box's left edge (caret ${m.caret[0]}, edge ${m.innerLeft})`)+ ok(m.shadow === 'none' && m.outline === 'solid' && m.offset >= 2, `the ring is an outline held ${m.offset}px off the box, no hugging shadow (${m.shadow})`)+ ok(m.boxVisible === 'hidden' && m.overCaret === 0, `Moveable's leftover lines are not drawn over the caret (${m.boxVisible}, ${m.overCaret} hits)`)+ // pixels: the 2px strip just left of the caret, the caret's own height+ const shot = await p.screenshot({ clip: { x: m.caret[0] - 2, y: m.caret[1] + 3, width: 2, height: Math.max(4, m.caret[2] - 6) } })+ const blue = await p.evaluate(async (b64) => {+ const img = new Image(); img.src = 'data:image/png;base64,' + b64; await img.decode()+ const c = document.createElement('canvas'); c.width = img.width; c.height = img.height+ const x = c.getContext('2d'); x.drawImage(img, 0, 0)+ const d = x.getImageData(0, 0, img.width, img.height).data+ let n = 0; for (let i = 0; i < d.length; i += 4) if (d[i + 2] - d[i] > 60 && d[i + 2] > 150) n+++ return n+ }, shot.toString('base64'))+ ok(blue === 0, `no ring-blue pixel in the strip beside the caret (${blue})`)+ const during = await textAt()+ ok(during[0] === before[0] && during[1] === before[1], `the text did not move when editing started (${before} → ${during})`)+ await p.keyboard.press('Escape')+ await p.waitForTimeout(200)+ await p.mouse.click(nb.x + 80, nb.y + 20)+ await p.waitForTimeout(250)+ const back = await p.evaluate(() => { const b = document.querySelector('.ed-stage-scale .moveable-control-box'); return b ? getComputedStyle(b).visibility : 'none' })+ ok(back === 'visible', `after the edit, the selected box shows its controls again (${back})`)+ ok(errors.length === 0, `no page errors${errors.length ? ': ' + errors.join('; ') : ''}`)+ await p.close()+ }+} finally { await browser.close() }++console.log(`\n${checks - failures}/${checks} checks passed`)+process.exit(failures ? 1 : 0)diff --git a/slides/src/styles.css b/slides/src/styles.cssindex 646c0e88..49423d60 100644--- a/slides/src/styles.css+++ b/slides/src/styles.css@@ -585,13 +585,23 @@ a.ed-btn { text-decoration: none; } /* the update block's "What's new" link iswhich would otherwise win and leave a shadowed element unfaded. */.ed-stage .bento-el-ghost-cut { filter: opacity(.35) !important; pointer-events: none; }.ed-stage .bento-editing { cursor: text; }+/* The caret at the start of a line sits on the text box's left edge — text+ starts flush with the element, and its geometry is the model's, so the text+ cannot move. Everything drawn ON that edge hid the caret (#547): the ring+ (a 1.5px shadow hugging it), the browser's focus outline, and Moveable's+ left line, still drawn from the last selection though it has no target+ while you edit. So the ring is an outline held 3px OUT, replacing the focus+ outline, and the idle control box is hidden for the edit. */.ed-stage .bento-editing .bento-text-inner {cursor: text;user-select: text;- box-shadow: 0 0 0 1.5px var(--blue);+ outline: 1.5px solid var(--blue);+ outline-offset: 3px;background: rgb(91 141 239 / 0.06);min-height: 1em;}+/* !important: Moveable writes display/visibility inline (as .ed-reader does) */+.ed-stage-scale:has(.bento-editing) .moveable-control-box { visibility: hidden !important; }/* ————— properties panel ————— */