From 275b07139d2fae07ef7fa731c5720fbefaf9267f Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 16 Oct 2026 18:12:01 +0000 Subject: [PATCH] Return keyboard focus to the button that started an action Every action runs through runExclusive, which disables the action buttons while it works. Disabling the focused button dropped keyboard focus to the page, so after Scan folder, Make preview sheets, Make cover or Upscale images a keyboard user was back at the top. Focus now returns to the button that started the action, unless it was moved elsewhere in the meantime. Checked in Chromium: by keyboard it comes back with its focus ring, by mouse without one, as before. The README gains two things it was missing: scan-folder's available_subfolders field, and that upscaling again replaces its earlier files, where sheets are never overwritten. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01FtCFQJ6wEFf5pZSL2HSE8G --- CHANGELOG.md | 2 ++ README.md | 6 ++++++ src/pasteup/static/js/app.js | 12 ++++++++++-- tests/test_ui_generation_modes.py | 10 ++++++++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bc71f6..3c4d114 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,8 @@ All notable changes to Pasteup are recorded here. The format follows those drives, and the `__MACOSX` folder left by unpacking a zip made on a Mac, are no longer offered as bundles. Covers no longer take images from them, nor from a `---Created---` folder inside the bundle. +- After a scan or making images, keyboard focus returns to the button that + started it, instead of falling back to the top of the page. ## [0.1.0] - 2026-10-16 diff --git a/README.md b/README.md index 78aa313..f14bac7 100644 --- a/README.md +++ b/README.md @@ -165,6 +165,8 @@ Behavior defaults: - Images per page: `12` (fixed 4x3). - Export naming: `page_001`, `page_002`, ... - Export conflict handling: never overwrite existing `page_###`; continue at next index. +- Upscaled images keep their image's name, in `Upscaled/PNG` and `Upscaled/JPG`, + so upscaling again replaces the files the last run made. --- @@ -194,6 +196,10 @@ Validates a folder and scans for supported image files. - `image_count` (int): number of supported files found. - `sample_files` (list[str]): up to 5 sorted sample filenames. - `estimated_pages` (int): `image_count // 12` (whole pages only). +- `available_subfolders` (list): when the folder has no images of its own, the + folders inside it, each with `display_name` and `full_path`, for picking one + bundle or listing many. Hidden folders, `__MACOSX` and `---Created---` are + left out. Empty when the folder has images. - `message` (str): summary or error detail. ### `POST /api/jobs/browse-folder` diff --git a/src/pasteup/static/js/app.js b/src/pasteup/static/js/app.js index aab90c1..fd3bfce 100644 --- a/src/pasteup/static/js/app.js +++ b/src/pasteup/static/js/app.js @@ -163,17 +163,24 @@ function describeErrorResponse(response, data) { } // One request-backed action at a time: while it runs, the action buttons are -// disabled, so a second click cannot start a duplicate export. +// disabled, so a second click cannot start a duplicate export. Disabling the +// focused button drops keyboard focus to the page, so afterwards it goes back +// to that button, rather than leaving a keyboard user at the top of the page. async function runExclusive(action) { if (generationState.busy) { return; } + const startedFrom = document.activeElement; setBusy(true); try { await action(); } finally { setBusy(false); + // Unless focus has been put somewhere else in the meantime. + if (document.activeElement === document.body && startedFrom !== document.body && startedFrom?.isConnected) { + startedFrom.focus(); + } } } @@ -1867,7 +1874,8 @@ async function useBrowsedFolder() { resetScanReadyState(); resetCoverCollageIncludeList(); await runExclusive(scanFolderAndCheckBundles); - // The scan disables Browse, which drops keyboard focus back to the page. + // Where closing the dialog didn't hand focus back to Browse, there was no + // button for runExclusive to return it to. if (document.activeElement === document.body) { browseFolderButton?.focus(); } diff --git a/tests/test_ui_generation_modes.py b/tests/test_ui_generation_modes.py index 7445e53..70e92c4 100644 --- a/tests/test_ui_generation_modes.py +++ b/tests/test_ui_generation_modes.py @@ -147,6 +147,16 @@ def test_app_js_reads_result_details_from_fields_not_prose() -> None: assert 'result.backgrounds_cleaned > 0' in script +def test_app_js_returns_focus_to_the_button_that_started_an_action() -> None: + """Disabling the focused button used to leave keyboard users at the top of the page.""" + script = APP_JS.read_text() + run_exclusive = script[script.index("async function runExclusive(action) {") :] + run_exclusive = run_exclusive[: run_exclusive.index("\n}\n")] + + assert "const startedFrom = document.activeElement;" in run_exclusive + assert "startedFrom.focus();" in run_exclusive + + def test_app_js_routes_every_request_through_the_error_aware_helper() -> None: """A failed request used to render as "Finished — Done.".""" script = APP_JS.read_text()