Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

slides: clicking a slide no longer makes the slide list jump (#839)

nyblnet77909c8dd32a
diff --git a/.github/workflows/ci-slides.yml b/.github/workflows/ci-slides.yml
index d07aa830..ff3014fa 100644
--- a/.github/workflows/ci-slides.yml
+++ b/.github/workflows/ci-slides.yml
@@ -162,6 +162,11 @@ jobs:
# range across a parent copies parents only, never its states; plural
# and singular toasts.
run: node scripts/test-slides-copy-slides-browser.mjs
+ - name: Clicking a slide never moves the list under the pointer in Chromium
+ # With the current slide scrolled out of view, a click on a visible
+ # thumb (plain, hidden, parent, state) leaves the list and the thumb
+ # where they were; keyboard navigation still reveals the current slide.
+ run: node scripts/test-slides-sidebar-click-browser.mjs
- name: Rounded tables in Chromium
# A rounded table whose rows outgrow its box shows its last row (#494),
# keeps rounded corners on its real bottom, and a short one still
diff --git a/scripts/test-slides-sidebar-click-browser.mjs b/scripts/test-slides-sidebar-click-browser.mjs
new file mode 100644
index 00000000..073887eb
--- /dev/null
+++ b/scripts/test-slides-sidebar-click-browser.mjs
@@ -0,0 +1,139 @@
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 The Bento authors
+// Clicking a slide in the list never moves the list under the pointer.
+//
+// npm run build:single --prefix slides && node scripts/test-slides-sidebar-click-browser.mjs
+//
+// WHAT THIS PROVES, in the packaged document. The slide list scrolls the
+// current slide into view. A click on a thumb clears the multi-selection
+// first and moves the current slide second, and clearing repainted the list
+// with the current slide still the OLD one — so when that slide was scrolled
+// out of view, the list jumped up to it, then down to the clicked thumb, which
+// ended up at an edge with a different slide under the pointer (reported with
+// hidden and state slides, which make lists long; any long list did it).
+// On a deck with hidden slides and nested state slides, with the previously
+// current slide off-screen ABOVE or BELOW:
+// 1. clicking a fully visible thumb — plain, hidden, a parent, a state —
+// leaves the list's scroll position and the thumb exactly where they were,
+// and the clicked slide is the one under the pointer;
+// 2. clicking a thumb that is only partly visible may reveal it, and the
+// clicked slide is still the one under the pointer;
+// 3. moving the current slide from the keyboard still brings an off-screen
+// thumb into view (the reveal is kept, only aimed at real changes).
+import { readFileSync, writeFileSync, mkdtempSync } from 'node:fs'
+import { tmpdir } from 'node:os'
+import { join } from 'node:path'
+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 shell = readFileSync(new URL('../slides/dist-single/Bento_Slides.bento.html', import.meta.url), 'utf8')
+const dir = mkdtempSync(join(tmpdir(), 'bento-sidebar-click-'))
+// 18 slides: s04 and s11 hidden; s06 has two states, s13 has one
+const slides = []
+const add = (id, extra = {}) => slides.push({ id, background: '#ffffff', transition: 'none', notes: '', elements: [{ id: 't-' + id, type: 'text', x: 100, y: 100, w: 800, h: 120, html: `<p>${id}</p>` }], ...extra })
+for (let n = 1; n <= 13; n++) {
+ const id = 's' + String(n).padStart(2, '0')
+ add(id, n === 4 || n === 11 ? { hidden: true } : {})
+ if (n === 6) { add('s06a', { stateOf: 's06' }); add('s06b', { stateOf: 's06' }) }
+ if (n === 13) add('s13a', { stateOf: 's13' })
+}
+add('s14'); add('s15')
+const doc = { format: 'bento/slides', version: 1, docId: 'sidebar-click', title: 'sidebar', size: { width: 1280, height: 720 }, theme: { background: '#ffffff', color: '#1E2A3A', accent: '#f7a600', fontFamily: 'system-ui' }, slides }
+const open = '<script type="application/bento+json" id="bento-doc">', close = '</' + 'script>'
+const at = shell.indexOf(open) + open.length
+const file = join(dir, 'deck.bento.html')
+writeFileSync(file, shell.slice(0, at) + JSON.stringify(doc).replace(/</g, '\\u003c') + shell.slice(shell.indexOf(close, at)))
+
+const browser = await chromium.launch({ executablePath: process.env.CHROME_PATH, headless: true })
+try {
+ const ctx = await browser.newContext({ viewport: { width: 1440, height: 800 } })
+ await ctx.route(/^https?:/, (r) => r.abort())
+ await ctx.addInitScript(() => { try { localStorage.setItem('bento-slideshow-started', '1') } catch {} })
+ const p = await ctx.newPage()
+ const errors = []
+ p.on('pageerror', (e) => errors.push(e.message))
+ await p.goto('file://' + file)
+ await p.waitForFunction(() => window.bento?.doc && document.querySelector('.ed-sidebar .ed-thumb'), null, { timeout: 20000 })
+ await p.waitForTimeout(800)
+
+ const idx = (id) => slides.findIndex((s) => s.id === id)
+ const geom = (id) => p.evaluate((i) => {
+ const sb = document.querySelector('.ed-sidebar'), sr = sb.getBoundingClientRect()
+ const r = sb.querySelector(`.ed-thumb[data-index="${i}"]`).getBoundingClientRect()
+ return { scroll: Math.round(sb.scrollTop), top: Math.round(r.top), bottom: Math.round(r.bottom), visTop: Math.round(sr.top), visBottom: Math.round(sr.top + sb.clientHeight) }
+ }, idx(id))
+ const under = (x, y) => p.evaluate(([x, y]) => { const t = document.elementFromPoint(x, y)?.closest('.ed-thumb'); return t ? window.bento.doc.slides[Number(t.dataset.index)]?.id : null }, [x, y])
+ // make `from` current without touching the list's scroll, then scroll the list to `scroll`
+ const setUp = async (from, scroll) => {
+ await p.evaluate((i) => document.querySelectorAll('.ed-sidebar .ed-thumb')[i].click(), idx(from))
+ await p.waitForTimeout(200)
+ await p.evaluate((y) => { document.querySelector('.ed-sidebar').scrollTop = y }, scroll)
+ await p.waitForTimeout(150)
+ }
+ const click = async (target) => {
+ const g = await geom(target)
+ const x = 60, y = Math.max(g.top, g.visTop) + 12
+ await p.mouse.click(x, y)
+ await p.waitForTimeout(500)
+ return { before: g, after: await geom(target), under: await under(x, y) }
+ }
+
+ console.log('a fully visible thumb, the current slide scrolled out of view\n')
+ // [current slide (off-screen), list scroll, target, what the target is]
+ for (const [from, scroll, target, what] of [
+ ['s01', 400, 's08', 'a plain slide (current one above, off-screen)'],
+ ['s01', 300, 's06', 'a parent with states'],
+ ['s01', 300, 's06a', 'a state slide'],
+ ['s01', 500, 's11', 'a hidden slide'],
+ ['s15', 0, 's03', 'a plain slide (current one below, off-screen)'],
+ ['s15', 0, 's04', 'a hidden slide (current one below)'],
+ ]) {
+ await setUp(from, scroll)
+ const pre = await geom(from)
+ const g0 = await geom(target)
+ const fully = g0.top >= g0.visTop && g0.bottom <= g0.visBottom
+ const offscreen = pre.bottom <= pre.visTop || pre.top >= pre.visBottom
+ if (!fully || !offscreen) { ok(false, `${what}: set-up (target fully visible ${fully}, ${from} off-screen ${offscreen})`); continue }
+ const r = await click(target)
+ ok(r.after.scroll === r.before.scroll && Math.abs(r.after.top - r.before.top) <= 1 && r.under === target,
+ `${what}: list stays put — scroll ${r.before.scroll}→${r.after.scroll}, thumb ${r.before.top}→${r.after.top}px, under the pointer: ${r.under}`)
+ }
+
+ console.log('\na partly visible thumb\n')
+ {
+ await setUp('s01', 0)
+ // pick the first thumb that straddles the bottom edge
+ const target = await p.evaluate(() => {
+ const sb = document.querySelector('.ed-sidebar'), bot = sb.getBoundingClientRect().top + sb.clientHeight
+ const t = [...sb.querySelectorAll('.ed-thumb')].find((n) => { const r = n.getBoundingClientRect(); return r.top < bot - 20 && r.bottom > bot })
+ return t ? window.bento.doc.slides[Number(t.dataset.index)].id : null
+ })
+ if (!target) ok(false, 'set-up: a thumb straddling the bottom edge')
+ else {
+ const r = await click(target)
+ ok(r.under === target, `${target}, partly visible: it may be revealed (scroll ${r.before.scroll}→${r.after.scroll}), and it is still the one under the pointer (${r.under})`)
+ }
+ }
+
+ console.log('\nkeyboard navigation still reveals\n')
+ {
+ await setUp('s01', 0)
+ await p.mouse.click(700, 400) // the canvas, nothing selected: arrows walk slides
+ await p.keyboard.press('Escape')
+ for (let i = 0; i < 12; i++) { await p.keyboard.press('PageDown'); await p.waitForTimeout(60) }
+ await p.waitForTimeout(400)
+ const cur = await p.evaluate(() => window.bento.doc.slides[[...document.querySelectorAll('.ed-sidebar .ed-thumb')].findIndex((n) => n.classList.contains('active'))]?.id)
+ const g = cur ? await geom(cur) : null
+ ok(!!g && g.top >= g.visTop - 1 && g.bottom <= g.visBottom + 1, `after paging to ${cur} from the keyboard, its thumb is in view (${g ? `${g.top}–${g.bottom} within ${g.visTop}–${g.visBottom}` : 'no thumb'})`)
+ }
+ ok(errors.length === 0, `no page error${errors.length ? ' — ' + errors[0] : ''}`)
+} finally {
+ await browser.close()
+}
+console.log(`\n${checks - failures}/${checks} checks passed`)
+if (failures) process.exit(1)
diff --git a/slides/src/editor/editor.ts b/slides/src/editor/editor.ts
index a62addb1..2d30dd6d 100644
--- a/slides/src/editor/editor.ts
+++ b/slides/src/editor/editor.ts
@@ -154,6 +154,8 @@ export class Editor {
/** Name of a deck opened by DROP when no writable handle came with it. */
private openedAs?: string
private thumbTimer = 0
+ /** The slide the list last scrolled into view (highlightSidebar). */
+ private thumbRevealed = -1
private presenting = false
private updatesB!: HTMLElement
private avatarsBox!: HTMLElement
@@ -2103,7 +2105,17 @@ export class Editor {
n.classList.toggle('selected', selected.has(idx))
if (isActive) active = n
})
- active?.scrollIntoView({ block: 'nearest', inline: 'nearest' })
+ // Bring the current slide into view only when it CHANGED. This also runs
+ // for a selection change and after a rebuild, with the current slide where
+ // it was — and a click on a thumb clears the selection BEFORE it moves the
+ // current slide, so revealing then scrolled the list to the slide being
+ // LEFT (often off-screen), and the click landed with a different thumb
+ // under the pointer. Keyboard and show navigation still reveal: they
+ // change the current slide.
+ if (active && this.store.currentIndex !== this.thumbRevealed) {
+ active.scrollIntoView({ block: 'nearest', inline: 'nearest' })
+ }
+ if (active) this.thumbRevealed = this.store.currentIndex
}
private scheduleThumbs() {