mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-01-04 03:48:07 +02:00
Cancel filter/search when hitting escape
This commit is contained in:
parent
a9e2c8129f
commit
84870d4503
@ -211,7 +211,7 @@ func (self *ContextMgr) deactivateContext(c types.Context, opts types.OnFocusLos
|
||||
}
|
||||
|
||||
if filterableContext, ok := c.(types.IFilterableContext); ok {
|
||||
if filterableContext.GetFilter() != "" {
|
||||
if filterableContext.IsFiltering() {
|
||||
filterableContext.ClearFilter()
|
||||
self.gui.helpers.Search.Cancel()
|
||||
}
|
||||
@ -247,12 +247,12 @@ func (self *ContextMgr) ActivateContext(c types.Context, opts types.OnFocusOpts)
|
||||
}
|
||||
|
||||
if searchableContext, ok := c.(types.ISearchableContext); ok {
|
||||
if searchableContext.GetSearchString() != "" {
|
||||
if searchableContext.IsSearching() {
|
||||
self.gui.helpers.Search.DisplaySearchPrompt(searchableContext)
|
||||
}
|
||||
}
|
||||
if filterableContext, ok := c.(types.IFilterableContext); ok {
|
||||
if filterableContext.GetFilter() != "" {
|
||||
if filterableContext.IsFiltering() {
|
||||
self.gui.helpers.Search.DisplayFilterPrompt(filterableContext)
|
||||
}
|
||||
}
|
||||
|
@ -68,3 +68,7 @@ func (self *SearchTrait) onSelectItemWrapper(innerFunc func(int) error) func(int
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SearchTrait) IsSearching() bool {
|
||||
return self.searchString != ""
|
||||
}
|
||||
|
@ -138,10 +138,6 @@ func (self *SearchHelper) ConfirmFilter() error {
|
||||
func (self *SearchHelper) ConfirmSearch() error {
|
||||
state := self.searchState()
|
||||
|
||||
if err := self.c.PopContext(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
context, ok := state.Context.(types.ISearchableContext)
|
||||
if !ok {
|
||||
self.c.Log.Warnf("Context %s is searchable", state.Context.GetKey())
|
||||
@ -153,6 +149,10 @@ func (self *SearchHelper) ConfirmSearch() error {
|
||||
|
||||
view := context.GetView()
|
||||
|
||||
if err := self.c.PopContext(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := view.Search(searchString); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -171,9 +171,10 @@ func (self *SearchHelper) Cancel() {
|
||||
|
||||
switch context := state.Context.(type) {
|
||||
case types.IFilterableContext:
|
||||
context.SetFilter("")
|
||||
context.ClearFilter()
|
||||
_ = self.c.PostRefreshUpdate(context)
|
||||
case types.ISearchableContext:
|
||||
context.ClearSearchString()
|
||||
context.GetView().ClearSearch()
|
||||
default:
|
||||
// do nothing
|
||||
|
@ -50,6 +50,19 @@ func (self *QuitActions) confirmQuitDuringUpdate() error {
|
||||
func (self *QuitActions) Escape() error {
|
||||
currentContext := self.c.CurrentContext()
|
||||
|
||||
switch ctx := currentContext.(type) {
|
||||
case types.IFilterableContext:
|
||||
if ctx.IsFiltering() {
|
||||
self.c.Helpers().Search.Cancel()
|
||||
return nil
|
||||
}
|
||||
case types.ISearchableContext:
|
||||
if ctx.IsSearching() {
|
||||
self.c.Helpers().Search.Cancel()
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
parentContext, hasParent := currentContext.GetParentContext()
|
||||
if hasParent && currentContext != nil && parentContext != nil {
|
||||
// TODO: think about whether this should be marked as a return rather than adding to the stack
|
||||
|
@ -93,6 +93,7 @@ type IFilterableContext interface {
|
||||
SetFilter(string)
|
||||
GetFilter() string
|
||||
ClearFilter()
|
||||
IsFiltering() bool
|
||||
IsFilterableContext()
|
||||
}
|
||||
|
||||
@ -102,6 +103,7 @@ type ISearchableContext interface {
|
||||
SetSearchString(string)
|
||||
GetSearchString() string
|
||||
ClearSearchString()
|
||||
IsSearching() bool
|
||||
IsSearchableContext()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user