Fix hidden root navigation and browser fill matching

This commit is contained in:
Joe Julian
2026-04-11 11:53:42 -07:00
parent c8f91b300b
commit e16067b345
9 changed files with 186 additions and 25 deletions
+65 -3
View File
@@ -23,6 +23,7 @@ import (
detaillayout "git.julianfamily.org/keepassgo/internal/appui/detail/layout"
"git.julianfamily.org/keepassgo/internal/clipboard"
"git.julianfamily.org/keepassgo/internal/session"
"git.julianfamily.org/keepassgo/internal/vault"
)
func (u *ui) bannerSurface() uiBanner {
@@ -552,10 +553,72 @@ func (u *ui) setCurrentPath(path []string) {
u.clearDeleteGroupConfirmation()
}
func copyPath(path []string) []string {
return append([]string(nil), path...)
}
func pathExistsInModel(model vault.Model, path []string) bool {
return len(model.EntriesInPath(path)) > 0 || len(model.ChildGroups(path)) > 0 || hasExactGroup(model, path)
}
func normalizeEntriesPathWithoutModel(path []string, root string) []string {
if root == "" {
return copyPath(path)
}
if len(path) == 0 {
return []string{root}
}
if path[0] == "Root" {
return append([]string{root}, path[1:]...)
}
return copyPath(path)
}
func (u *ui) normalizedEntriesPath(path []string) []string {
if u.state.Section != appstate.SectionEntries {
return copyPath(path)
}
root := u.hiddenVaultRoot()
model, err := u.state.Session.Current()
if err != nil {
return normalizeEntriesPathWithoutModel(path, root)
}
if len(path) == 0 {
if root == "" {
return nil
}
return []string{root}
}
if path[0] == "Root" && root != "" {
candidate := append([]string{root}, path[1:]...)
if pathExistsInModel(model, candidate) {
return candidate
}
}
if (len(path) == 1 && root != "" && path[0] == root) || pathExistsInModel(model, path) {
return copyPath(path)
}
if root == "" {
return copyPath(path)
}
return []string{root}
}
func (u *ui) adoptStateCurrentPath() {
path := u.normalizedEntriesPath(u.state.CurrentPath)
u.currentPath = append([]string(nil), path...)
u.state.CurrentPath = append([]string(nil), path...)
u.syncedPath = append([]string(nil), path...)
u.syncPhoneGroupBrowser(path)
if len(u.deleteGroupPath) > 0 && !slices.Equal(u.deleteGroupPath, u.currentPath) {
u.clearDeleteGroupConfirmation()
}
}
func (u *ui) syncCurrentPath() {
switch {
case slices.Equal(u.currentPath, u.syncedPath) && !slices.Equal(u.state.CurrentPath, u.syncedPath):
u.currentPath = append([]string(nil), u.state.CurrentPath...)
u.adoptStateCurrentPath()
case !slices.Equal(u.currentPath, u.syncedPath) && slices.Equal(u.state.CurrentPath, u.syncedPath):
u.state.CurrentPath = append([]string(nil), u.currentPath...)
case !slices.Equal(u.currentPath, u.syncedPath) && !slices.Equal(u.state.CurrentPath, u.syncedPath):
@@ -1217,8 +1280,7 @@ func (u *ui) handleGroupClicks(gtx layout.Context) {
for u.moveGroup.Clicked(gtx) {
u.clearDeleteGroupConfirmation()
u.runAction("move group", u.moveCurrentGroupAction)
u.currentPath = append([]string(nil), u.state.CurrentPath...)
u.syncedPath = append([]string(nil), u.state.CurrentPath...)
u.adoptStateCurrentPath()
u.filter()
}
for u.toggleGroupControls.Clicked(gtx) {