Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "Mark Range": reduce maximum namespaces in favorites, fix shadowing of ctrl+space #2927

Merged
merged 6 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 6 additions & 1 deletion internal/view/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,12 @@ func (b *Browser) namespaceActions(aa *ui.KeyActions) {
if ns == client.NamespaceAll {
continue
}
aa.Add(ui.NumKeys[index], ui.NewKeyAction(ns, b.switchNamespaceCmd, true))
numKey := ui.Key0 + tcell.Key(index)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all we need here is to make sure the key is within the index range.

		if k, ok := ui.NumKeys[index]; ok {
			aa.Add(k, ui.NewKeyAction(ns, b.switchNamespaceCmd, true))
			b.namespaces[index] = ns
			index++
		} else {
			log.Warn().Msgf("No more keys available for namespace %s: %d of %d]. Skipping...", ns, index, data.MaxFavoritesNS)
		}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright 👍 will change it. However maybe the index++ needs to be after the if/else block, otherwise index will just remain stuck on a missing key and wouldn't correspond with the namespace index. Or we can just assume that keys are no longer available and break after the warning

Copy link
Contributor Author

@zkck zkck Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the check, here we can see the output (I set MaxFavoriteNS back to 10 to test this)

Screenshot from 2024-10-31 10-06-12

// no assumption is made about the length of FavNamespaces
if numKey > ui.Key9 {
break
}
aa.Add(numKey, ui.NewKeyAction(ns, b.switchNamespaceCmd, true))
b.namespaces[index] = ns
index++
}
Expand Down