Skip to content

Commit

Permalink
Merge pull request #134 from itsmewes/feature/global-tree-search
Browse files Browse the repository at this point in the history
Add a global tree search keyboard shortcut
  • Loading branch information
jorgerojas26 authored Feb 1, 2025
2 parents 65b46fa + e1b8d86 commit a5c8564
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/keymap.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var Keymaps = KeymapSystem{
Bind{Key: Key{Char: 'q'}, Cmd: cmd.Quit, Description: "Quit"},
Bind{Key: Key{Code: tcell.KeyBackspace2}, Cmd: cmd.SwitchToConnectionsView, Description: "Switch to connections list"},
Bind{Key: Key{Char: '?'}, Cmd: cmd.HelpPopup, Description: "Help"},
Bind{Key: Key{Code: tcell.KeyCtrlP}, Cmd: cmd.SearchGlobal, Description: "Global search"},
},
ConnectionGroup: {
Bind{Key: Key{Char: 'n'}, Cmd: cmd.NewConnection, Description: "Create a new database connection"},
Expand Down
3 changes: 3 additions & 0 deletions commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const (
Save
Delete
Search
SearchGlobal
Quit
Execute
OpenInExternalEditor
Expand Down Expand Up @@ -140,6 +141,8 @@ func (c Command) String() string {
return "Delete"
case Search:
return "Search"
case SearchGlobal:
return "SearchGlobal"
case Quit:
return "Quit"
case Execute:
Expand Down
9 changes: 9 additions & 0 deletions components/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,15 @@ func (home *Home) homeInputCapture(event *tcell.EventKey) *tcell.EventKey {
// })
mainPages.AddPage(pageNameHelp, home.HelpModal, true, true)
}
case commands.SearchGlobal:
if table != nil && !table.GetIsEditing() && !table.GetIsFiltering() && home.FocusedWrapper == focusedWrapperRight {
home.focusLeftWrapper()
}

home.Tree.ForceRemoveHighlight()
home.Tree.ClearSearch()
app.App.SetFocus(home.Tree.Filter)
home.Tree.SetIsFiltering(true)
}

return event
Expand Down
16 changes: 9 additions & 7 deletions components/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,19 +187,14 @@ func NewTree(dbName string, dbdriver drivers.Driver) *Tree {
filterText := tree.Filter.GetText()

if filterText == "" {
tree.search("")
tree.FoundNodeCountInput.SetText("")
tree.SetBorderPadding(0, 0, 0, 0)
tree.ClearSearch()
} else {
tree.FoundNodeCountInput.SetText(fmt.Sprintf("[%d/%d]", len(tree.state.searchFoundNodes), len(tree.state.searchFoundNodes)))
tree.SetBorderPadding(1, 0, 0, 0)
}

case tcell.KeyEscape:
tree.search("")
tree.FoundNodeCountInput.SetText("")
tree.SetBorderPadding(0, 0, 0, 0)
tree.Filter.SetText("")
tree.ClearSearch()
}

tree.SetIsFiltering(false)
Expand Down Expand Up @@ -585,3 +580,10 @@ func (tree *Tree) Refresh(dbName string) {
// re-add nodes
tree.InitializeNodes(dbName)
}

func (tree *Tree) ClearSearch() {
tree.search("")
tree.FoundNodeCountInput.SetText("")
tree.SetBorderPadding(0, 0, 0, 0)
tree.Filter.SetText("")
}

0 comments on commit a5c8564

Please sign in to comment.