From 99d47ab7e70bd2c2e721e506d1976228d0a58fed Mon Sep 17 00:00:00 2001 From: Zak Cook Date: Sat, 9 Nov 2024 20:26:36 +0100 Subject: [PATCH] Fix "Mark Range": reduce maximum namespaces in `favorites`, fix shadowing of ctrl+space (#2927) * fix: avoid creating a ctrl+space key when index out of range * fix: reduce maximum favorite namespaces to 9, making space for "all" * fix: correct index incrementation * refactor: remove usage of NumKeys * feat: check for favorite namespace index in NumKeys * feat: break when out of number keys, increment index when slot found --- internal/config/data/ns.go | 2 +- internal/view/browser.go | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/internal/config/data/ns.go b/internal/config/data/ns.go index fb1a515b..0e0e2228 100644 --- a/internal/config/data/ns.go +++ b/internal/config/data/ns.go @@ -12,7 +12,7 @@ import ( const ( // MaxFavoritesNS number # favorite namespaces to keep in the configuration. - MaxFavoritesNS = 10 + MaxFavoritesNS = 9 ) // Namespace tracks active and favorites namespaces. diff --git a/internal/view/browser.go b/internal/view/browser.go index 7f0876d1..d5c9cfdf 100644 --- a/internal/view/browser.go +++ b/internal/view/browser.go @@ -585,13 +585,19 @@ func (b *Browser) namespaceActions(aa *ui.KeyActions) { aa.Add(ui.Key0, ui.NewKeyAction(client.NamespaceAll, b.switchNamespaceCmd, true)) b.namespaces[0] = client.NamespaceAll index := 1 - for _, ns := range b.app.Config.FavNamespaces() { + favNamespaces := b.app.Config.FavNamespaces() + for _, ns := range favNamespaces { if ns == client.NamespaceAll { continue } - aa.Add(ui.NumKeys[index], ui.NewKeyAction(ns, b.switchNamespaceCmd, true)) - b.namespaces[index] = ns - index++ + if numKey, ok := ui.NumKeys[index]; ok { + aa.Add(numKey, ui.NewKeyAction(ns, b.switchNamespaceCmd, true)) + b.namespaces[index] = ns + index++ + } else { + log.Warn().Msgf("No number key available for favorite namespace %s (%d of %d). Skipping...", ns, index, len(favNamespaces)) + break + } } }