Skip to content

fix: let enter press a dialog's default button as soon as it opens - #570

Merged
Tiaxi merged 1 commit into
mainfrom
fix/dialog-enter-on-open
Nov 10, 2026
Merged

Tiaxi merged 1 commit into
mainfrom
fix/dialog-enter-on-open

Conversation

@Tiaxi

@Tiaxi Tiaxi commented Nov 10, 2026

Copy link
Copy Markdown
Owner

What changes

When one of these dialogs opened, Enter did nothing until keyboard focus moved into the dialog, for example after pressing Tab:

  • the shared confirmation (ConfirmDialog)
  • the tag editor's close, quit and reload question
  • the rename preview
  • Auto Number
  • the quit-time save failure
  • the quit wait, once it offers its choices

Qt gives the keyboard to the popup itself. Keys go from the focused item to its parents and never into its children, so the Enter handler on the dialog's content (DialogButtons.handleEnter) never saw the key. On Qt 6.11, DialogButtonBox.defaultButton gives the default button the focus, which hid the bug on some opening paths but not on others.

A new shared component, PopupInitialFocus, gives the dialog's content the keyboard each time the popup becomes visible. That happens before the fade-in, so an Enter pressed as the dialog appears reaches the content's handler. It uses only public API (Popup.visible and Item.forceActiveFocus). Each affected dialog declares it next to its PopupClosing.

These behaviours are unchanged:

  • Tab goes on from the content through the dialog: first the header's close button, then the buttons. Each time the dialog shows, focus starts in the content again, not on the button Tab last left it on.
  • Escape still cancels, including right as the dialog appears.
  • fix: take no second click while a confirmation fades out #558's closing guard: Enter during the closing fade does not run the action a second time.
  • fix: keep the tag question's buttons when its default changes #561's default button: Enter presses whichever button is the default at that moment. On the reload question that is Discard and Reload. In a text field, Enter still only accepts the text.

Dialogs without a primary button

Diagnostics, TagEditorStatusDetails and ItunesArtwork have no default button and no Enter handler. Enter still does nothing in them, by design. This PR does not touch them.

Tests

Each affected dialog is opened through its real trigger. The test then presses Enter right away, without moving focus first, and checks that the default action runs exactly once. It also checks that Enter during the closing fade does nothing more, that Escape at once cancels, and, for the two confirmations, that Tab reaches the buttons without leaving the dialog.

  • PreferencesSmokeTest::enterConfirmsAsSoonAsTheConfirmationShows (ConfirmDialog, through Clear in Diagnostics)
  • ErrorsSmokeTest::enterRetriesAsSoonAsTheSaveFailureShows
  • TagEditorSmokeTest::enterAnswersTheTagEditorsQuestionAsSoonAsItShows (close, reload and save paths)
  • TagEditorSmokeTest::enterKeepsWaitingOnceTheQuitWaitOffersIt (Enter does nothing before the choice appears, then presses Keep Waiting)
  • TagEditorSmokeTest::enterNumbersTracksAsSoonAsAutoNumberShows
  • TagEditorSmokeTest::enterRenamesAsSoonAsThePreviewShows

With the six dialogs reverted to main, all six tests fail at the focus check. With that check stubbed out as well, the Enter checks of four of them still fail. The confirmation and the tag editor question pass that run on Qt 6.11.2, because Qt focuses their default button on these paths.

The tests are session-independent: they use the existing smoke harness, which calls TestSessionIsolation.h, runs offscreen and uses temporary user directories.

Closes #562

Qt gives the keyboard to a popup itself when it opens, and keys go from
the focused item to its parents, never into its children: the Enter
handler on a dialog's content did not see the key until focus moved into
the dialog. Qt 6.11's default button focus hid this on some opening
paths only.

PopupInitialFocus gives the content the keyboard each time the popup
shows, before it fades in. The shared confirmation, the tag editor's
question, the rename preview, Auto Number, the quit-time save failure
and the quit wait use it. Tab, Escape, the closing guard and the
current default button work as before.

Closes #562
@Tiaxi
Tiaxi merged commit c0c000f into main Nov 10, 2026
5 checks passed
@Tiaxi
Tiaxi deleted the fix/dialog-enter-on-open branch November 10, 2026 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Enter should press a dialog's default button as soon as it opens

1 participant