From 2a3069e1e53091e1e09a76ad6a407ac12b319913 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Mon, 20 Jan 2025 09:39:27 +0000 Subject: [PATCH 1/2] :bug: Fix focus getting lost when the details panel is closed Fixes #114. --- ChangeLog.md | 3 +++ src/braindrop/app/screens/main.py | 14 +++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index 2f6c917..f5435fd 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -8,6 +8,9 @@ editing dialog now style locally-known tags differently from suggestions that haven't ever been used by the user. ([#115](https://github.com/davep/braindrop/pull/115)) +- Fixed focus getting lost for a moment if it was within the details panel + and the details panel was closed. + ([#114](https://github.com/davep/braindrop/issues/114)) ## v0.6.1 diff --git a/src/braindrop/app/screens/main.py b/src/braindrop/app/screens/main.py index ea6324d..d0d495b 100644 --- a/src/braindrop/app/screens/main.py +++ b/src/braindrop/app/screens/main.py @@ -436,8 +436,20 @@ def action_escape_command(self) -> None: def action_details_command(self) -> None: """Toggle the details of the raindrop details view.""" self.toggle_class("details-hidden") + if ( + hidden := self.has_class("details-hidden") + and self.focused is not None + and ( + self.focused is self.query_one(RaindropDetails) + or self.focused.parent is self.query_one(RaindropDetails) + ) + ): + # Focus was on the details, or within, so let's ensure it heads + # back to the list of raindrops as that feels like the most + # logical landing point. + self.set_focus(self.query_one(RaindropsView)) with update_configuration() as config: - config.details_visible = not self.has_class("details-hidden") + config.details_visible = not hidden @on(CompactMode) def action_compact_mode_command(self) -> None: From bea2d715ad5cd9179e47cd1b46eb49addf0103d6 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Mon, 20 Jan 2025 09:44:09 +0000 Subject: [PATCH 2/2] :hammer: Simplify focus test --- src/braindrop/app/screens/main.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/braindrop/app/screens/main.py b/src/braindrop/app/screens/main.py index d0d495b..d629391 100644 --- a/src/braindrop/app/screens/main.py +++ b/src/braindrop/app/screens/main.py @@ -439,10 +439,7 @@ def action_details_command(self) -> None: if ( hidden := self.has_class("details-hidden") and self.focused is not None - and ( - self.focused is self.query_one(RaindropDetails) - or self.focused.parent is self.query_one(RaindropDetails) - ) + and self.query_one(RaindropDetails) in (self.focused, self.focused.parent) ): # Focus was on the details, or within, so let's ensure it heads # back to the list of raindrops as that feels like the most