mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-12-02 09:21:40 +02:00
Only cancel search if main or temporary context loses focus
This is a pickle: initially I wanted it so that a filter would cancel automatically if the current context lost focus. But there are situations where you want to retain the focus, e.g. when a popup appears, or when you view the commits of a branch. The issue is that when you view the commits of a branch, the branches context is removed from the context stack. Even if this were not the case, you could imagine going branches -> sub-commits -> files -> sub-commits, where in that case branches would definitely be off the stack upon navigating to the files context. So because I'm too lazy to find a proper solution to this problem, I'm just making it so that filters in side contexts are retained unless explicitly cancelled. There's another edge case this commit handles which is that if I'm in the sub-commits context via the branches context and start a search, then navigate to the reflog context and hit enter to get to the sub-commits context again, I need to cancel the search before I switch. Likewise with the commit files context.
This commit is contained in:
parent
b8bee4de51
commit
13c1103815
@ -201,7 +201,10 @@ 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 {
|
||||
self.gui.helpers.Search.CancelSearchIfSearching(c)
|
||||
self.gui.helpers.Search.HidePrompt()
|
||||
if c.GetKind() == types.MAIN_CONTEXT || c.GetKind() == types.TEMPORARY_POPUP {
|
||||
self.gui.helpers.Search.CancelSearchIfSearching(c)
|
||||
}
|
||||
}
|
||||
|
||||
// if we are the kind of context that is sent to back upon deactivation, we should do that
|
||||
|
@ -41,15 +41,16 @@ func (self *SearchHelper) OpenFilterPrompt(context types.IFilterableContext) err
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SearchHelper) OpenSearchPrompt(context types.Context) error {
|
||||
func (self *SearchHelper) OpenSearchPrompt(context types.ISearchableContext) error {
|
||||
state := self.searchState()
|
||||
|
||||
state.Context = context
|
||||
searchString := context.GetSearchString()
|
||||
|
||||
self.searchPrefixView().SetContent(self.c.Tr.SearchPrefix)
|
||||
promptView := self.promptView()
|
||||
// TODO: should we show the currently searched thing here? Perhaps we can store that on the context
|
||||
promptView.ClearTextArea()
|
||||
promptView.TextArea.TypeString(searchString)
|
||||
promptView.RenderTextArea()
|
||||
|
||||
if err := self.c.PushContext(self.c.Contexts().Search); err != nil {
|
||||
@ -78,7 +79,8 @@ func (self *SearchHelper) DisplaySearchPrompt(context types.ISearchableContext)
|
||||
state.Context = context
|
||||
searchString := context.GetSearchString()
|
||||
|
||||
self.searchPrefixView().SetContent(self.c.Tr.SearchPrefix)
|
||||
_ = context.GetView().SelectCurrentSearchResult()
|
||||
|
||||
promptView := self.promptView()
|
||||
promptView.ClearTextArea()
|
||||
promptView.TextArea.TypeString(searchString)
|
||||
@ -179,7 +181,7 @@ func (self *SearchHelper) Cancel() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
state.Context = nil
|
||||
self.HidePrompt()
|
||||
}
|
||||
|
||||
func (self *SearchHelper) OnPromptContentChanged(searchString string) {
|
||||
@ -229,3 +231,8 @@ func (self *SearchHelper) CancelSearchIfSearching(c types.Context) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SearchHelper) HidePrompt() {
|
||||
state := self.searchState()
|
||||
state.Context = nil
|
||||
}
|
||||
|
@ -83,6 +83,7 @@ func (self *SwitchToDiffFilesController) viewFiles(opts SwitchToCommitFilesConte
|
||||
diffFilesContext.SetCanRebase(opts.CanRebase)
|
||||
diffFilesContext.SetParentContext(opts.Context)
|
||||
diffFilesContext.SetWindowName(opts.Context.GetWindowName())
|
||||
diffFilesContext.ClearFilter()
|
||||
|
||||
if err := self.c.Refresh(types.RefreshOptions{
|
||||
Scope: []types.RefreshableView{types.COMMIT_FILES},
|
||||
|
@ -71,12 +71,15 @@ func (self *SwitchToSubCommitsController) viewCommits() error {
|
||||
|
||||
self.setSubCommits(commits)
|
||||
|
||||
self.c.Contexts().SubCommits.SetSelectedLineIdx(0)
|
||||
self.c.Contexts().SubCommits.SetParentContext(self.context)
|
||||
self.c.Contexts().SubCommits.SetWindowName(self.context.GetWindowName())
|
||||
self.c.Contexts().SubCommits.SetTitleRef(ref.Description())
|
||||
self.c.Contexts().SubCommits.SetRef(ref)
|
||||
self.c.Contexts().SubCommits.SetLimitCommits(true)
|
||||
subCommitsContext := self.c.Contexts().SubCommits
|
||||
subCommitsContext.SetSelectedLineIdx(0)
|
||||
subCommitsContext.SetParentContext(self.context)
|
||||
subCommitsContext.SetWindowName(self.context.GetWindowName())
|
||||
subCommitsContext.SetTitleRef(ref.Description())
|
||||
subCommitsContext.SetRef(ref)
|
||||
subCommitsContext.SetLimitCommits(true)
|
||||
subCommitsContext.ClearSearchString()
|
||||
subCommitsContext.GetView().ClearSearch()
|
||||
|
||||
err = self.c.PostRefreshUpdate(self.c.Contexts().SubCommits)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user