fix(web): a dialog opened with the mouse hands the keyboard back to the terminal

After App Settings or Session Options was opened with a mouse click and
closed, nothing typed reached the terminal until it was clicked again.
FocusTrap saved document.activeElement when the dialog opened, and by then
the press had already moved focus: onto the pressed control in Chromium and
Firefox, onto <body> in WebKit on macOS, where a button takes no focus from
the mouse.

FocusTrap.focusToReturn() is what a dialog saves now. A pointerdown listener
records the typing field that had focus when a mouse press began (pointerdown
comes before mousedown, whose default action moves focus), and that field is
the answer when focus sits on the pressed control or on <body> as the dialog
opens. Any key forgets the press, so a control reached with the keyboard gets
focus back as before. Only a typing field is remembered, for one press (a
press on a menu item inherits it from the press that opened the menu) and
only for a mouse, so touch is unchanged. Asking spends the press, so nothing
pressed inside the opening dialog can hand the keyboard to a field behind it.

The command palette and the Session Manager save the same answer.

Measured in Chromium against a running server: App Settings and Session
Options opened by mouse ended on the clicked gear before and in the terminal
after, also with the press clearing focus as WebKit on macOS does, with the
tile grid and the split open (the keyboard returns to the pane it was in),
and through a tile's menu. Not run in WebKit on macOS itself.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Codeman maintainer committed 2026-11-25 10:23:52 +01:00
1 parent 5548c17c4a
commit 79f85415d8
7 files changed
+756 -2

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"aicodeman": patch
---
**Closing a dialog you opened with the mouse puts the keyboard back in the terminal.** After App Settings or Session Options was opened with a click and closed again, nothing you typed reached the terminal until you clicked it: focus was left on the button you had clicked, and in Safari and the Mac app on nothing at all. A dialog now returns the keyboard to the field you were typing in when you clicked, which with the tile grid or the split open is the pane you were in. The Session Manager and the command palette follow the same rule. A dialog opened with the keyboard still returns to the control it was opened from.