From 2a48974e82da96ee76606aaf22b529c82900f7d9 Mon Sep 17 00:00:00 2001 From: yetone Date: Mon, 9 Nov 2026 18:10:41 +0800 Subject: [PATCH] gui: a redraw with no copy of the pressed element marks the focus it gives, as before 9dd7aabca 9dd7aabca stopped openModal's focus from marking the dialog's hold on every redraw, so a refresh pressed among alike rows stays held. In WebKit, which doesn't focus a button on click, that left the hold on a button the redraw took away (Codex's Sign out, then the ask's Cancel). holdModal then fell back to the focused element with the old element's depth (modalHold.y), moved the dialog by the difference, and its ResizeObserver reported a loop: codex-signout "webkit en: Codex's only account signs out, asked first" red 3 of 3, green 3 of 3 at its parent a6a99717e. Now the focus given back skips the mark only when there is a copy of the pressed element to hold (the element kept through the redraw, or the focused one of several alike); otherwise it marks it as before. Found by serving app.js with each part of 9dd7aabca turned off in turn: only the refocus guard took the red away. Core: 1,533,732 (budget 1,533,802), no raise. Run at this head, rebased on b8270850d (wsl-run, Linux, Playwright 1.62.0): - codex-signout, account-refresh-holds and builtin-places (main's new GUI file): 110 of 110 ok. - go test -tags nogui ./internal/gui -run 'Budget|I18n|Dates': ok. The whole package hit go test's 10m default on WSL; a 30m run is going. Before the rebase, on a6a99717e: - codex-signout.test.cjs, 3 times: 24 of 24 ok each time - account-refresh-holds.test.cjs and click-scroll.test.cjs: account-refresh-holds 4 of 4 ok; click-scroll ok but for its WebKit late-heard wheel (#4385) - go test -tags nogui ./internal/gui -run 'Budget|I18n|Dates': ok After 9dd7aabca, the rest of the 203 GUI files that reach #modal ran to a 3600s cap; every other red there is red the same at a6a99717e and filed: model-chip-steady #4388, i18n-keys #5332, icon-url #4688, inner-scroll-contain #4689, menu-input-scroll #3402, mcp-hub-direct #4701, ledger-hscroll (red 2 of 3 at a6a99717e too) #4400, click-scroll's late-heard wheel #4385. Not tried: the real Wails app. --- internal/gui/assets/app.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index b6efbed53..c5b32abf7 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -9002,10 +9002,11 @@ function openModal(content, quiet) { || focusIndex >= 0 && content.querySelectorAll("input, textarea, select, button")[focusIndex]; // the focus given back is not a press: what was pressed stays held, by // the element a redraw put back or by the focused copy of it - modalRefocus = !fresh; + const copy = held && (content.contains(held) ? held : held === active && focus) || null; + modalRefocus = !!copy; try { (focus || content.querySelector("input:not([disabled]), textarea, select, button:not([disabled])") || d).focus(NO_SCROLL); } finally { modalRefocus = false; } - if (held) modalHold.copy = content.contains(held) ? held : held === active && focus || null; + modalHold.copy = copy; const body = content.querySelector(":scope > .ebody"); if (body) body.scrollTop = top; // a re-render keeps the place const nextNames = content.querySelector(".mnames:not([hidden])");