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

Add a global tree search keyboard shortcut #134

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
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 @@ -342,6 +342,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("")
}