diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2023-05-28 13:25:52 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2023-07-03 12:54:14 +1000 |
commit | d67b209e62f8254d5f17ecdb8fe7ff810f000566 (patch) | |
tree | 220b15b574abaf5a68cfa030f25ac3d2f58bf586 | |
parent | bf5871cc4fe8bd7f431e5603447ea0bc29b3d642 (diff) |
Move more logic into search helper
-rw-r--r-- | pkg/gui/context.go | 27 | ||||
-rw-r--r-- | pkg/gui/controllers/helpers/search_helper.go | 33 |
2 files changed, 35 insertions, 25 deletions
diff --git a/pkg/gui/context.go b/pkg/gui/context.go index 7c669cbff..1c235a93f 100644 --- a/pkg/gui/context.go +++ b/pkg/gui/context.go @@ -201,21 +201,7 @@ func (self *ContextMgr) deactivateContext(c types.Context, opts types.OnFocusLos view, _ := self.gui.c.GocuiGui().View(c.GetViewName()) if opts.NewContextKey != context.SEARCH_CONTEXT_KEY { - - if searchableContext, ok := c.(types.ISearchableContext); ok { - if view != nil && view.IsSearching() { - view.ClearSearch() - searchableContext.ClearSearchString() - self.gui.helpers.Search.Cancel() - } - } - - if filterableContext, ok := c.(types.IFilterableContext); ok { - if filterableContext.IsFiltering() { - filterableContext.ClearFilter() - self.gui.helpers.Search.Cancel() - } - } + self.gui.helpers.Search.CancelSearchIfSearching(c) } // if we are the kind of context that is sent to back upon deactivation, we should do that @@ -246,16 +232,7 @@ func (self *ContextMgr) ActivateContext(c types.Context, opts types.OnFocusOpts) return err } - if searchableContext, ok := c.(types.ISearchableContext); ok { - if searchableContext.IsSearching() { - self.gui.helpers.Search.DisplaySearchPrompt(searchableContext) - } - } - if filterableContext, ok := c.(types.IFilterableContext); ok { - if filterableContext.IsFiltering() { - self.gui.helpers.Search.DisplayFilterPrompt(filterableContext) - } - } + self.gui.helpers.Search.DisplaySearchInfoIfSearching(c) desiredTitle := c.Title() if desiredTitle != "" { diff --git a/pkg/gui/controllers/helpers/search_helper.go b/pkg/gui/controllers/helpers/search_helper.go index e825fba3e..f8bfcbd9c 100644 --- a/pkg/gui/controllers/helpers/search_helper.go +++ b/pkg/gui/controllers/helpers/search_helper.go @@ -195,3 +195,36 @@ func (self *SearchHelper) OnPromptContentChanged(searchString string) { // do nothing (shouldn't land here) } } + +func (self *SearchHelper) DisplaySearchInfoIfSearching(c types.Context) { + if searchableContext, ok := c.(types.ISearchableContext); ok { + if searchableContext.IsSearching() { + self.DisplaySearchPrompt(searchableContext) + } + } + if filterableContext, ok := c.(types.IFilterableContext); ok { + if filterableContext.IsFiltering() { + self.DisplayFilterPrompt(filterableContext) + } + } +} + +func (self *SearchHelper) CancelSearchIfSearching(c types.Context) { + if searchableContext, ok := c.(types.ISearchableContext); ok { + view := searchableContext.GetView() + if view != nil && view.IsSearching() { + view.ClearSearch() + searchableContext.ClearSearchString() + self.Cancel() + } + return + } + + if filterableContext, ok := c.(types.IFilterableContext); ok { + if filterableContext.IsFiltering() { + filterableContext.ClearFilter() + self.Cancel() + } + return + } +} |