1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-04 10:34:55 +02:00

Fix escape logic for remote branches

The remote branches controller was using its own escape method meaning it didn't go through the flow of cancelling
an active filter. It's now using the same approach as the sub-commits and commit-files contexts: defining a parent
context to return to upon hittin escape.
This commit is contained in:
Jesse Duffield 2023-06-03 19:55:17 +10:00
parent 261f30f49c
commit cd989d8ebe
4 changed files with 66 additions and 13 deletions

View File

@ -59,11 +59,6 @@ func (self *RemoteBranchesController) GetKeybindings(opts types.KeybindingsOpts)
Handler: self.checkSelected(self.setAsUpstream),
Description: self.c.Tr.SetAsUpstream,
},
{
Key: opts.GetKey(opts.Config.Universal.Return),
Handler: self.escape,
Description: self.c.Tr.ReturnToRemotesList,
},
{
Key: opts.GetKey(opts.Config.Commits.ViewResetOptions),
Handler: self.checkSelected(self.createResetMenu),
@ -115,10 +110,6 @@ func (self *RemoteBranchesController) checkSelected(callback func(*models.Remote
}
}
func (self *RemoteBranchesController) escape() error {
return self.c.PushContext(self.c.Contexts().Remotes)
}
func (self *RemoteBranchesController) delete(selectedBranch *models.RemoteBranch) error {
message := fmt.Sprintf("%s '%s'?", self.c.Tr.DeleteRemoteBranchMessage, selectedBranch.FullName())

View File

@ -104,14 +104,16 @@ func (self *RemotesController) enter(remote *models.Remote) error {
if len(remote.Branches) == 0 {
newSelectedLine = -1
}
self.c.Contexts().RemoteBranches.SetSelectedLineIdx(newSelectedLine)
self.c.Contexts().RemoteBranches.SetTitleRef(remote.Name)
remoteBranchesContext := self.c.Contexts().RemoteBranches
remoteBranchesContext.SetSelectedLineIdx(newSelectedLine)
remoteBranchesContext.SetTitleRef(remote.Name)
remoteBranchesContext.SetParentContext(self.Context())
if err := self.c.PostRefreshUpdate(self.c.Contexts().RemoteBranches); err != nil {
if err := self.c.PostRefreshUpdate(remoteBranchesContext); err != nil {
return err
}
return self.c.PushContext(self.c.Contexts().RemoteBranches)
return self.c.PushContext(remoteBranchesContext)
}
func (self *RemotesController) add() error {

View File

@ -0,0 +1,59 @@
package filter_and_search
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var FilterRemoteBranches = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Filtering remote branches",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.NewBranch("branch-apple")
shell.EmptyCommit("commit-one")
shell.NewBranch("branch-grape")
shell.NewBranch("branch-orange")
shell.CloneIntoRemote("origin")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Remotes().
Focus().
Lines(
Contains(`origin`).IsSelected(),
).
PressEnter()
t.Views().RemoteBranches().
IsFocused().
Lines(
Contains(`branch-apple`).IsSelected(),
Contains(`branch-grape`),
Contains(`branch-orange`),
).
FilterOrSearch("grape").
Lines(
Contains(`branch-grape`).IsSelected(),
).
// cancel the filter
PressEscape().
Tap(func() {
t.Views().Search().IsInvisible()
}).
Lines(
Contains(`branch-apple`),
Contains(`branch-grape`).IsSelected(),
Contains(`branch-orange`),
).
// return to remotes view
PressEscape()
t.Views().Remotes().
IsFocused().
Lines(
Contains(`origin`).IsSelected(),
)
},
})

View File

@ -98,6 +98,7 @@ var tests = []*components.IntegrationTest{
filter_and_search.FilterCommitFiles,
filter_and_search.FilterFiles,
filter_and_search.FilterMenu,
filter_and_search.FilterRemoteBranches,
filter_and_search.NestedFilter,
filter_and_search.NestedFilterTransient,
filter_by_path.CliArg,