Repository navigation
Restore focus after closing a modal - #1010
Open
Luca Zani (OverloadedTech) wants to merge 1 commit into
Open
Luca Zani (OverloadedTech) wants to merge 1 commit into
Luca Zani (OverloadedTech) wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #614
modal_beginmoves the focus into the modal, but nothing gives it back when the modal closes. The focus path still points into the closed modal, sopop_focusable_nodetrims it down to the root and the text area takes the focus again throughinherit_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_nodetrims 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 --workspaceand 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.