Skip to content

Commit

Permalink
Fix "Mark Range": reduce maximum namespaces in favorites, fix shado…
Browse files Browse the repository at this point in the history
…wing 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
  • Loading branch information
zkck authored Nov 9, 2024
1 parent 59918d0 commit 99d47ab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion internal/config/data/ns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 10 additions & 4 deletions internal/view/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down

0 comments on commit 99d47ab

Please sign in to comment.