From 2af722b283c5cbe03e4c59235dc9453552750360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9otime=20Marcopoulos?= Date: Thu, 6 Nov 2025 15:55:12 +0100 Subject: [PATCH] feat(config): add keybinds to cycle focus between widgets (#613) Co-authored-by: Ayyan --- cmd/application.go | 28 ++++++++++++++++++++++++++++ internal/config/config.toml | 3 +++ internal/config/keys.go | 2 ++ 3 files changed, 33 insertions(+) diff --git a/cmd/application.go b/cmd/application.go index 21e8152..b29da83 100644 --- a/cmd/application.go +++ b/cmd/application.go @@ -137,6 +137,34 @@ func (a *application) onPagesInputCapture(event *tcell.EventKey) *tcell.EventKey case a.cfg.Keys.FocusMessageInput: a.SetFocus(a.messageInput) return nil + case a.cfg.Keys.FocusPrevious: + switch a.GetFocus() { + case a.guildsTree: + a.SetFocus(a.messageInput) + case a.messageInput: + a.SetFocus(a.messagesList) + default: // Handle both a.messagesList and a.flex as well as other edge cases (if there is). + if a.flex.GetItemCount() == 2 { + a.SetFocus(a.guildsTree) + } else { // If there is no guild tree, the correct previous page is message input. + a.SetFocus(a.messageInput) + } + } + return nil + case a.cfg.Keys.FocusNext: + switch a.GetFocus() { + case a.guildsTree: + a.SetFocus(a.messagesList) + case a.messagesList: + a.SetFocus(a.messageInput) + default: // Handle both a.messageInput and a.flex as well as other edge cases (if there is). + if a.flex.GetItemCount() == 2 { + a.SetFocus(a.guildsTree) + } else { // If there is no guild tree, the correct next page is message input. + a.SetFocus(a.messagesList) + } + } + return nil case a.cfg.Keys.Logout: a.quit() diff --git a/internal/config/config.toml b/internal/config/config.toml index ca63fa5..65b2896 100644 --- a/internal/config/config.toml +++ b/internal/config/config.toml @@ -37,6 +37,9 @@ only_on_ping = true focus_guilds_tree = "Ctrl+G" focus_messages_list = "Ctrl+T" focus_message_input = "Ctrl+Space" +# Cycle focus between the widgets. +focus_previous = "Ctrl+H" +focus_next = "Ctrl+L" # Hide/show the guilds tree. toggle_guilds_tree = "Ctrl+B" quit = "Ctrl+C" diff --git a/internal/config/keys.go b/internal/config/keys.go index c18e016..e2e2e02 100644 --- a/internal/config/keys.go +++ b/internal/config/keys.go @@ -12,6 +12,8 @@ type ( FocusGuildsTree string `toml:"focus_guilds_tree"` FocusMessagesList string `toml:"focus_messages_list"` FocusMessageInput string `toml:"focus_message_input"` + FocusPrevious string `toml:"focus_previous"` + FocusNext string `toml:"focus_next"` ToggleGuildsTree string `toml:"toggle_guilds_tree"` GuildsTree GuildsTreeKeys `toml:"guilds_tree"`