1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-04 22:34:39 +02:00

Move more logic into search helper

This commit is contained in:
Jesse Duffield 2023-05-28 13:25:52 +10:00
parent bf5871cc4f
commit d67b209e62
2 changed files with 35 additions and 25 deletions

View File

@ -201,21 +201,7 @@ func (self *ContextMgr) deactivateContext(c types.Context, opts types.OnFocusLos
view, _ := self.gui.c.GocuiGui().View(c.GetViewName()) view, _ := self.gui.c.GocuiGui().View(c.GetViewName())
if opts.NewContextKey != context.SEARCH_CONTEXT_KEY { if opts.NewContextKey != context.SEARCH_CONTEXT_KEY {
self.gui.helpers.Search.CancelSearchIfSearching(c)
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()
}
}
} }
// if we are the kind of context that is sent to back upon deactivation, we should do that // 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 return err
} }
if searchableContext, ok := c.(types.ISearchableContext); ok { self.gui.helpers.Search.DisplaySearchInfoIfSearching(c)
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)
}
}
desiredTitle := c.Title() desiredTitle := c.Title()
if desiredTitle != "" { if desiredTitle != "" {

View File

@ -195,3 +195,36 @@ func (self *SearchHelper) OnPromptContentChanged(searchString string) {
// do nothing (shouldn't land here) // 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
}
}