Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

type: Find button and Cmd-F open the find box again (#734)

nyblnet8fdacb43b932
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index aa4c7ace..1f6bb7ea 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -2340,6 +2340,29 @@ jobs:
# The last section is two real sessions over a real BroadcastChannel.
run: node --no-warnings scripts/test-sync-spaces-session.ts
+ type-find-browser:
+ runs-on: ubuntu-latest
+ timeout-minutes: 15
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-node@v4
+ with:
+ node-version: 24
+ - name: Install browser test runtime
+ # Pinned outside app packages: browser automation is not shipped in documents.
+ run: |
+ npm install --prefix "$RUNNER_TEMP/bento-browser" --no-package-lock --ignore-scripts [email protected]
+ "$RUNNER_TEMP/bento-browser/node_modules/.bin/playwright" install --with-deps chromium
+ echo "PLAYWRIGHT_MODULE=$RUNNER_TEMP/bento-browser/node_modules/playwright/index.mjs" >> "$GITHUB_ENV"
+ - name: Build the tested standalone document
+ run: |
+ npm ci --prefix type
+ npm run build:single --prefix type
+ - name: Find opens from the button, Cmd-F and Ctrl-F
+ # The find box lives in Navigate → Results; a selector naming a tab
+ # that no longer existed made both do nothing, silently.
+ run: node scripts/test-type-find-browser.mjs
+
slides-font-browser:
runs-on: ubuntu-latest
timeout-minutes: 15
diff --git a/scripts/test-type-find-browser.mjs b/scripts/test-type-find-browser.mjs
new file mode 100644
index 00000000..61feb883
--- /dev/null
+++ b/scripts/test-type-find-browser.mjs
@@ -0,0 +1,73 @@
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 The Bento authors
+// Find and replace opens from the toolbar button, ⌘F and Ctrl+F.
+//
+// npm run build:single --prefix type && node scripts/test-type-find-browser.mjs
+//
+// WHY. The find box lives in the Navigate tab's Results view. find.ts opened
+// it by clicking `.t-tabs button[data-tab="find"]`, a tab that no longer
+// existed: the selector matched nothing, nothing threw, and the button and ⌘F
+// did nothing at all. Find was reachable only by opening Navigate → Results
+// by hand. A node rig cannot see that, so this one uses the packaged editor
+// and real input.
+//
+// WHAT THIS PROVES, for each way of opening find, from each starting state
+// (side panel hidden, the Review tab showing, the Pages view showing): the
+// find box ends up on screen, it has the keyboard focus, and typing in it
+// really searches (the count reports matches).
+//
+// Mutation (run, judged by exit code): restore the old `data-tab="find"`
+// selector in find.ts showPanel → every opening row goes red.
+const { chromium } = await import(process.env.PLAYWRIGHT_MODULE || 'playwright')
+
+let checks = 0, failures = 0
+const ok = (c, m) => { checks++; if (!c) { failures++; console.log(` FAIL ${m}`) } else console.log(` ok ${m}`) }
+
+const SHELL = new URL('../type/dist-single/Bento_Type.bento.html', import.meta.url).href
+const OPENERS = {
+ 'the toolbar button': (p) => p.click('#tool-find'),
+ '⌘F': (p) => p.keyboard.press('Meta+f'),
+ 'Ctrl+F': (p) => p.keyboard.press('Control+f'),
+}
+const STARTS = {
+ 'the editor as it opens': async () => {},
+ 'the side panel hidden': async (p) => {
+ await p.click('#sidebar')
+ await p.waitForFunction(() => document.querySelector('.t-main').classList.contains('t-side-off'))
+ },
+ 'the Review tab showing': (p) => p.click('.t-tabs button[data-tab="review"]'),
+ 'the Pages view showing': (p) => p.click('#navSeg button[data-view="pages"]'),
+}
+
+const browser = await chromium.launch({ executablePath: process.env.CHROME_PATH, headless: true })
+try {
+ for (const [startName, start] of Object.entries(STARTS)) {
+ for (const [openName, open] of Object.entries(OPENERS)) {
+ const p = await browser.newPage({ viewport: { width: 1440, height: 900 } })
+ await p.route(/^https?:/, (r) => r.abort())
+ await p.goto(SHELL)
+ await p.waitForFunction(() => window.bento?.doc && document.querySelector('#paper p[data-kind=para]'))
+ // the caret in the document, where a person is when they reach for ⌘F
+ const bb = await p.locator('#paper p[data-kind=para]').first().boundingBox()
+ await p.mouse.click(bb.x + 4, bb.y + bb.height / 2)
+ await start(p)
+ const hiddenBefore = await p.evaluate(() => !document.querySelector('.t-find-q').getBoundingClientRect().width)
+ await open(p)
+ await p.waitForTimeout(200)
+ const s = await p.evaluate(() => {
+ const q = document.querySelector('.t-find-q'), r = q.getBoundingClientRect()
+ return { shown: r.width > 0 && r.height > 0, focused: document.activeElement === q }
+ })
+ await p.keyboard.type('Payment')
+ await p.waitForTimeout(300)
+ const count = await p.evaluate(() => document.querySelector('.t-find-count')?.textContent?.trim() ?? '')
+ ok(hiddenBefore && s.shown && s.focused && /[1-9]/.test(count),
+ `from ${startName}, ${openName} opens find: the box was hidden, is now on screen (${s.shown}) and focused (${s.focused}), and typing searches ("${count}")`)
+ await p.close()
+ }
+ }
+} finally {
+ await browser.close()
+}
+console.log(`\n${checks - failures}/${checks} checks passed`)
+if (failures) process.exit(1)
diff --git a/type/src/find.ts b/type/src/find.ts
index 414c7b29..a7fa9882 100644
--- a/type/src/find.ts
+++ b/type/src/find.ts
@@ -511,7 +511,13 @@ let panel: FindPanel | null = null;
*/
function showPanel(): void {
document.querySelector('.t-main')?.classList.remove('t-side-off');
- document.querySelector<HTMLElement>('.t-tabs button[data-tab="find"]')?.click();
+ // The find box lives in the Navigate tab's Results view (main.ts), not in a
+ // tab of its own: open the tab, then the view. A selector naming a tab that
+ // no longer exists matches nothing and fails SILENTLY — that is how the
+ // button and ⌘F once did nothing at all — so the browser rig opens find
+ // both ways and checks the box is on screen and focused.
+ document.querySelector<HTMLElement>('.t-tabs button[data-tab="navigate"]')?.click();
+ document.querySelector<HTMLElement>('#navSeg button[data-view="results"]')?.click();
}
// The house icon recipe, from icons.ts: 24 box, 16 render, currentColor,