Skip to content

Commit

Permalink
better handling of clearing the search
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed Feb 24, 2020
1 parent 1f5ccab commit 78b62be
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/gui/branches_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func (gui *Gui) onBranchesTabClick(tabIndex int) error {
func (gui *Gui) switchBranchesPanelContext(context string) error {
branchesView := gui.getBranchesView()
branchesView.Context = context
branchesView.ClearSearch()
gui.onSearchEscape()

contextTabIndexMap := map[string]int{
"local-branches": 0,
Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/commits_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ func (gui *Gui) onCommitsTabClick(tabIndex int) error {
func (gui *Gui) switchCommitsPanelContext(context string) error {
commitsView := gui.getCommitsView()
commitsView.Context = context
commitsView.ClearSearch()
gui.onSearchEscape()

contextTabIndexMap := map[string]int{
"branch-commits": 0,
Expand Down
3 changes: 1 addition & 2 deletions pkg/gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,7 @@ func (gui *Gui) onFocusLost(v *gocui.View, newView *gocui.View) error {
return nil
}
if v.IsSearching() && newView.Name() != "search" {
gui.State.Searching.isSearching = false
v.ClearSearch()
gui.onSearchEscape()
}
switch v.Name() {
case "branches":
Expand Down
10 changes: 6 additions & 4 deletions pkg/gui/searching.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ func (gui *Gui) onSelectItemWrapper(innerFunc func(int) error) func(int, int, in

func (gui *Gui) onSearchEscape() error {
gui.State.Searching.isSearching = false
gui.State.Searching.view = nil
if gui.State.Searching.view != nil {
gui.State.Searching.view.ClearSearch()
gui.State.Searching.view = nil
}

return nil
}

Expand All @@ -81,9 +85,7 @@ func (gui *Gui) handleSearchEscape(g *gocui.Gui, v *gocui.View) error {
return err
}

if err := gui.onSearchEscape(); err != nil {
return err
}
gui.onSearchEscape()

return nil
}

0 comments on commit 78b62be

Please sign in to comment.