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
mine
Zak Cook 2024-11-09 20:26:36 +01:00 committed by GitHub
parent 59918d0e89
commit 99d47ab7e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 5 deletions

View File

@ -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.

View File

@ -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
}
}
}