Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

slides: the top bar holds still — the Saved note overlays the title, the file chip keeps its slot (#546) (#690)

nyblnet0f0e4807f8ba
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 1898639e..5e4fe4bd 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -2354,6 +2354,11 @@ jobs:
# primary in both themes, and N language rebuilds leaving one set of
# window/document listeners and bar observers.
run: node scripts/test-slides-topbar-browser.mjs
+ - name: Top bar holds still in Chromium
+ # #546: a real auto-save "Saved" flash and a file-chip change (rename to
+ # the file's name, then undo) leave Undo/Redo exactly where they were,
+ # on the desktop and the folded phone bar.
+ run: node scripts/test-slides-topbar-stable-browser.mjs
- name: Chrome rulings in Chromium
# D2 menu descriptions (readable both themes, ARIA-wired, scroll on a
# short window), D4 dialog titles, D8 help shortcuts, the compact Save
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e9c3622a..4bf42d7c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,12 @@ pre-1.0.
## [Unreleased]
+- **The top bar no longer shifts under your pointer.** Each auto-save's
+ "Saved" note, and the file name beside the deck title appearing or
+ disappearing, used to push the buttons after them sideways — so when you
+ pressed Undo a few times in a row, a click could land on Redo instead. The
+ note now shows over the end of the title, and the file name keeps its place.
+ Reported in #546.
- **Pasting onto another slide keeps the position.** Copy a logo, a header or
any element and paste it onto a different slide, and it lands exactly where
it was. It steps down and right only when it would cover the same element
diff --git a/scripts/test-slides-topbar-stable-browser.mjs b/scripts/test-slides-topbar-stable-browser.mjs
new file mode 100644
index 00000000..2aa39eef
--- /dev/null
+++ b/scripts/test-slides-topbar-stable-browser.mjs
@@ -0,0 +1,98 @@
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 The Bento authors
+// The top bar never moves under the pointer (#546).
+//
+// npm run build:single --prefix slides && node scripts/test-slides-topbar-stable-browser.mjs
+//
+// WHAT THIS PROVES, in the packaged editor with real input. Auto-save flashed
+// "Saved" as a FLEX ITEM after the deck title, and the file chip toggled
+// display whenever the title matched the file name — both pushed every control
+// after them sideways, so while someone undid repeatedly the Undo button moved
+// under the pointer and the click landed on Redo. Now:
+// 1. through a real ⌘S and a real auto-save write-back, the "Saved" flash
+// appears (visibly, inside the bar) while Undo and Redo stay exactly put;
+// 2. renaming the deck to its file's name, and undoing that, leaves Undo and
+// Redo exactly put (the chip keeps its slot and only goes quiet);
+// 3. the same on the folded phone bar.
+// File writes go to a stub handle (the File System Access picker), so nothing
+// touches disk.
+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 {
+ for (const [label, width, height] of [['desktop', 1440, 900], ['phone', 390, 844]]) {
+ console.log(`\n${label} (${width}px)\n`)
+ const ctx = await browser.newContext({ viewport: { width, height } })
+ await ctx.route(/^https?:/, (r) => r.abort())
+ await ctx.addInitScript(() => {
+ const handle = { name: 'stable-test.bento.html', kind: 'file',
+ async queryPermission() { return 'granted' }, async requestPermission() { return 'granted' },
+ async createWritable() { return { async write() {}, async close() {} } } }
+ window.showSaveFilePicker = async () => handle
+ })
+ const p = await ctx.newPage()
+ const errors = []
+ p.on('pageerror', (e) => errors.push(e.message))
+ p.on('dialog', (d) => d.accept())
+ await p.goto(new URL('../slides/dist-single/Bento_Slides.bento.html', import.meta.url).href)
+ await p.waitForFunction(() => window.bento?.doc && document.querySelector('.ed-topbar'))
+ await p.waitForTimeout(400)
+ // the controls a click can land on, by their tooltip (stable across tiers)
+ const rects = () => p.evaluate(() => Object.fromEntries(['Undo (⌘Z)', 'Redo (⇧⌘Z)'].map((t) => {
+ const b = [...document.querySelectorAll('.ed-topbar .ed-btn')].find((x) => x.title === t && x.getBoundingClientRect().width)
+ const r = b?.getBoundingClientRect()
+ return [t, r ? `${r.x.toFixed(1)},${r.y.toFixed(1)},${r.width.toFixed(1)}` : 'missing']
+ })))
+ const same = (a, b) => JSON.stringify(a) === JSON.stringify(b)
+
+ // a first save gives the deck a file (and a handle for auto-save)
+ await p.keyboard.press(`${MOD}+s`)
+ await p.waitForTimeout(600)
+ const base = await rects()
+ // the folded phone bar keeps Undo; Redo moves into ⋯ by design
+ ok(base['Undo (⌘Z)'] !== 'missing' && (label === 'phone' || base['Redo (⇧⌘Z)'] !== 'missing'),
+ `${label === 'phone' ? 'Undo is' : 'Undo and Redo are'} on the bar (${JSON.stringify(base)})`)
+
+ // a real auto-save write-back flashes "Saved"
+ await p.locator('.ed-title').fill('Stability check')
+ await p.locator('.ed-title').press('Tab')
+ await p.waitForSelector('.ed-autosaved.show', { timeout: 6000 }).catch(() => {})
+ const during = await rects()
+ const tag = await p.evaluate(() => {
+ const t = document.querySelector('.ed-autosaved.show'), bar = document.querySelector('.ed-topbar')
+ if (!t) return null
+ const r = t.getBoundingClientRect(), b = bar.getBoundingClientRect()
+ return { text: t.textContent, inBar: r.top >= b.top - 1 && r.bottom <= b.bottom + 1 && r.width > 0, opacity: +getComputedStyle(t).opacity }
+ })
+ ok(!!tag && tag.inBar, `the "Saved" flash shows, inside the bar (${JSON.stringify(tag)})`)
+ ok(same(base, during), `Undo and Redo do not move while it shows (${JSON.stringify(during)})`)
+ await p.waitForTimeout(2000)
+ ok(same(base, await rects()), 'nor after it fades')
+
+ // the title matches the file name, then an undo brings the old one back
+ await p.locator('.ed-title').fill('stable-test')
+ await p.locator('.ed-title').press('Tab')
+ await p.waitForTimeout(300)
+ const quiet = await rects()
+ ok(same(base, quiet), `renaming the deck to its file's name leaves them put (${JSON.stringify(quiet)})`)
+ await p.mouse.click(10, height - 10) // off the title, so ⌘Z is the deck's undo
+ await p.keyboard.press(`${MOD}+z`)
+ await p.waitForTimeout(300)
+ const undone = await p.evaluate(() => window.bento.doc.title)
+ ok(undone !== 'stable-test' && same(base, await rects()), `and so does undoing it (title "${undone}")`)
+
+ ok(errors.length === 0, `no page errors${errors.length ? ': ' + errors.join('; ') : ''}`)
+ await ctx.close()
+ }
+} finally { await browser.close() }
+
+console.log(`\n${checks - failures}/${checks} checks passed`)
+process.exit(failures ? 1 : 0)
diff --git a/slides/src/editor/editor.ts b/slides/src/editor/editor.ts
index 6468986b..3f24d36a 100644
--- a/slides/src/editor/editor.ts
+++ b/slides/src/editor/editor.ts
@@ -2820,7 +2820,10 @@ export class Editor {
? `${this.store.doc.title} — ${file}`
: `${this.store.doc.title} — ${appConfig().appName}`
if (!this.fileChip) return
- this.fileChip.hidden = !named
+ // out of the bar only until there IS a file; after that the chip keeps its
+ // slot and goes quiet when it would repeat the title (styles.css, #546)
+ this.fileChip.hidden = !file
+ this.fileChip.classList.toggle('ed-filechip-quiet', !named)
if (!file) return
this.fileChip.textContent = fileBase(file)
// Three states, because two would lie: with the API but no handle yet, ⌘S
@@ -3102,21 +3105,23 @@ export class Editor {
}
private savedTimer = 0
- private savedHideTimer = 0
private flashSaved(message = t('Saved')) {
- let tag = document.querySelector<HTMLElement>('.ed-autosaved')
- if (!tag) { tag = div('ed-autosaved'); document.querySelector('.ed-topbar .ed-title')?.after(tag) }
+ const title = document.querySelector<HTMLElement>('.ed-topbar .ed-title')
+ const bar = title?.parentElement
+ if (!title || !bar) return
+ let tag = bar.querySelector<HTMLElement>(':scope > .ed-autosaved')
+ if (!tag) { tag = div('ed-autosaved'); bar.appendChild(tag) }
tag.textContent = message
- // hidden while idle: at opacity 0 the tag still held its width, so after
- // the first backup the title permanently lost the space this text needs
- tag.hidden = false
+ // An overlay at the title's right end, never a slot in the bar: as a flex
+ // item it shifted Undo/Redo on every auto-save and clicks landed on Redo
+ // (#546). Offsets are in the bar's content coordinates, so it rides along
+ // when a too-narrow bar is scrolled.
+ tag.style.left = `${Math.max(title.offsetLeft, title.offsetLeft + title.offsetWidth - tag.offsetWidth - 6)}px`
+ tag.style.top = `${title.offsetTop + (title.offsetHeight - tag.offsetHeight) / 2}px`
void tag.offsetWidth // paint a frame at opacity 0 so the fade-in runs
tag.classList.add('show')
clearTimeout(this.savedTimer)
- clearTimeout(this.savedHideTimer)
this.savedTimer = window.setTimeout(() => tag!.classList.remove('show'), 1400)
- // leave layout only after the 0.25s fade-out has finished
- this.savedHideTimer = window.setTimeout(() => { tag!.hidden = true }, 1700)
}
async save(forcePicker: boolean) {
diff --git a/slides/src/styles.css b/slides/src/styles.css
index c7eb4106..646c0e88 100644
--- a/slides/src/styles.css
+++ b/slides/src/styles.css
@@ -222,6 +222,10 @@ option { background: var(--field); color: var(--ink); }
cursor: default;
}
.ed-filechip[hidden] { display: none; }
+/* Known file, but its name would only repeat the title: keep the SLOT and
+ hide the text. Toggling display here reflowed the bar whenever an undo or a
+ rename made the title match the file name (#546). */
+.ed-filechip.ed-filechip-quiet { visibility: hidden; }
.ed-topbar.ed-bar-compact .ed-filechip { display: none; }
/* unsaved-changes dot — badges the SAVE button's corner (amber when dirty) */
@@ -1121,13 +1125,22 @@ a.ed-btn { text-decoration: none; } /* the update block's "What's new" link is
max-width: min(92vw, 560px);
}
.ed-recover .ed-btn { padding: 5px 12px; }
+/* "Saved" / "Backed up in this browser" OVERLAYS the end of the deck title
+ (editor.ts flashSaved places it) instead of taking a slot in the bar. As a
+ flex item it pushed everything after it sideways on every auto-save, so the
+ Undo button moved under a pointer mid-click and the click landed on Redo
+ (#546). Inside the bar's own box, because at the narrowest widths the bar
+ is a scroll container and anything outside it would be clipped. */
+.ed-topbar { position: relative; }
.ed-autosaved {
+ position: absolute;
font-size: 11px;
- color: #6f8; /* set by theme below */
color: var(--muted);
+ background: var(--surface);
+ padding: 1px 4px;
+ border-radius: 4px;
opacity: 0;
transition: opacity 0.25s;
- align-self: center;
white-space: nowrap;
pointer-events: none;
}