Skip to content

Restore focus after closing a modal - #1010

Open
Luca Zani (OverloadedTech) wants to merge 1 commit into
microsoft:mainfrom
OverloadedTech:restore-modal-focus
Open

Luca Zani (OverloadedTech) wants to merge 1 commit into
microsoft:mainfrom
OverloadedTech:restore-modal-focus

Conversation

@OverloadedTech

Copy link
Copy Markdown

Fixes #614

modal_begin moves the focus into the modal, but nothing gives it back when the modal closes. The focus path still points into the closed modal, so pop_focusable_node trims it down to the root and the text area takes the focus again through inherit_focus. The search bar only closes on Escape while it has the focus, so after cancelling "Unsaved Changes" (or Go to Line) Escape did nothing and typing went into the document instead of the search field.

This saves the focus path when a modal first appears and restores it once the modal is gone, if the focus was still inside it. It's a stack because the overwrite warning can open on top of Save As. If the saved path no longer exists, pop_focusable_node trims it like before.

One side effect: after picking a language from the status bar, the focus now goes back to the status bar instead of the editor. The indentation and encoding pickers already behave that way, the language picker only ended up in the editor because of this bug. If you'd prefer the editor there I can change that.

Tested on macOS with nightly fmt, cargo test --workspace and clippy as in CI. tui.rs has no tests, so I drove edit in a pty before and after the change: Ctrl+F, Ctrl+Q with unsaved changes, Esc, Esc now closes the search bar, same with Ctrl+G instead of Ctrl+Q, and typing after the dialog goes into the search field. Go to Line from the editor still returns to the editor, and cancelling the overwrite warning still returns to the Save As file name. Haven't tried Windows.

When a modal closed, the focus path still pointed into it, so it got
trimmed down to the root and the text area took the focus. The search
bar only closes on Escape while it has the focus, so after cancelling
a dialog Escape no longer closed it.

Closes microsoft#614
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.

[bug] with unsaved changes, press ctrl+f, ctrl+q, Esc, Esc doesn't close the search bar as it should.

1 participant