Prevent focusing character input when closing dialogs

This commit is contained in:
Isaiah Odhner 2024-11-10 23:33:53 -05:00
parent 45b28f142f
commit d61de649a6
3 changed files with 3 additions and 1 deletions

View File

@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Plain text files (`.txt`) are now saved with CRLF line endings on Windows. - Plain text files (`.txt`) are now saved with CRLF line endings on Windows.
- When closing dialogs, the character input no longer becomes focused.
### Fixed ### Fixed

View File

@ -216,7 +216,6 @@ To preview ANSI art files in file managers like Nautilus, Thunar, Nemo, or Caja,
### Misc ### Misc
- Extraneous undo states may be created in some cases. In particular, I noticed when undoing/redoing with free-typing mode, the last state had no cursor but was otherwise identical. - Extraneous undo states may be created in some cases. In particular, I noticed when undoing/redoing with free-typing mode, the last state had no cursor but was otherwise identical.
- Document recovery dialog is shown unnecessarily if the backup file is identical. - Document recovery dialog is shown unnecessarily if the backup file is identical.
- Closing dialogs focuses the character input which is undesirable as it prevents typing in the canvas or copying the selection with <kbd>Ctrl</kbd>+<kbd>C</kbd> etc. (You can use <kbd>Esc</kbd> to reset focus.)
- Pressing a key to exit View Bitmap mode may cause unwanted side effects. - Pressing a key to exit View Bitmap mode may cause unwanted side effects.
- Pressing a key doesn't exit View Bitmap mode if the character input is focused. - Pressing a key doesn't exit View Bitmap mode if the character input is focused.

View File

@ -395,6 +395,8 @@ class Window(Container):
def close(self) -> None: def close(self) -> None:
"""Force close the window.""" """Force close the window."""
# Before removing from the DOM, unfocus, because otherwise Textual will try to focus a widget "nearby" in the focus order, in `_reset_focus`.
self.app.set_focus(None)
self.remove() self.remove()
self.post_message(self.Closed()) self.post_message(self.Closed())