mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-08-10 22:42:00 +02:00
Fix duplicate keybinding suggestions in status bar after switching repos (#3660)
- **PR Description** When switching to a repo that was open before, all keybinding suggestions in the status bar would show twice. Fixes #3612. - **Please check if the PR fulfills these requirements** * [x] Cheatsheets are up-to-date (run `go generate ./...`) * [x] Code has been formatted (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting)) * [x] Tests have been added/updated (see [here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md) for the integration test guide) * [ ] Text is internationalised (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation)) * [ ] Docs have been updated if necessary * [x] You've read through your own file changes for silly mistakes etc
This commit is contained in:
@@ -133,6 +133,11 @@ func (self *BaseContext) AddMouseKeybindingsFn(fn types.MouseKeybindingsFn) {
|
|||||||
self.mouseKeybindingsFns = append(self.mouseKeybindingsFns, fn)
|
self.mouseKeybindingsFns = append(self.mouseKeybindingsFns, fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *BaseContext) ClearAllBindingsFn() {
|
||||||
|
self.keybindingsFns = []types.KeybindingsFn{}
|
||||||
|
self.mouseKeybindingsFns = []types.MouseKeybindingsFn{}
|
||||||
|
}
|
||||||
|
|
||||||
func (self *BaseContext) AddOnClickFn(fn func() error) {
|
func (self *BaseContext) AddOnClickFn(fn func() error) {
|
||||||
if fn != nil {
|
if fn != nil {
|
||||||
self.onClickFn = fn
|
self.onClickFn = fn
|
||||||
|
@@ -20,6 +20,10 @@ func (gui *Gui) Helpers() *helpers.Helpers {
|
|||||||
// in the keybinding menu: the earlier that the controller is attached to a context,
|
// in the keybinding menu: the earlier that the controller is attached to a context,
|
||||||
// the lower in the list the keybindings will appear.
|
// the lower in the list the keybindings will appear.
|
||||||
func (gui *Gui) resetHelpersAndControllers() {
|
func (gui *Gui) resetHelpersAndControllers() {
|
||||||
|
for _, context := range gui.Contexts().Flatten() {
|
||||||
|
context.ClearAllBindingsFn()
|
||||||
|
}
|
||||||
|
|
||||||
helperCommon := gui.c
|
helperCommon := gui.c
|
||||||
recordDirectoryHelper := helpers.NewRecordDirectoryHelper(helperCommon)
|
recordDirectoryHelper := helpers.NewRecordDirectoryHelper(helperCommon)
|
||||||
reposHelper := helpers.NewRecentReposHelper(helperCommon, recordDirectoryHelper, gui.onNewRepo)
|
reposHelper := helpers.NewRecentReposHelper(helperCommon, recordDirectoryHelper, gui.onNewRepo)
|
||||||
|
@@ -74,6 +74,7 @@ type IBaseContext interface {
|
|||||||
|
|
||||||
AddKeybindingsFn(KeybindingsFn)
|
AddKeybindingsFn(KeybindingsFn)
|
||||||
AddMouseKeybindingsFn(MouseKeybindingsFn)
|
AddMouseKeybindingsFn(MouseKeybindingsFn)
|
||||||
|
ClearAllBindingsFn()
|
||||||
|
|
||||||
// This is a bit of a hack at the moment: we currently only set an onclick function so that
|
// This is a bit of a hack at the moment: we currently only set an onclick function so that
|
||||||
// our list controller can come along and wrap it in a list-specific click handler.
|
// our list controller can come along and wrap it in a list-specific click handler.
|
||||||
|
@@ -360,6 +360,12 @@ func (self *Shell) Clone(repoName string) *Shell {
|
|||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *Shell) CloneNonBare(repoName string) *Shell {
|
||||||
|
self.RunCommand([]string{"git", "clone", ".", "../" + repoName})
|
||||||
|
|
||||||
|
return self
|
||||||
|
}
|
||||||
|
|
||||||
func (self *Shell) SetBranchUpstream(branch string, upstream string) *Shell {
|
func (self *Shell) SetBranchUpstream(branch string, upstream string) *Shell {
|
||||||
self.RunCommand([]string{"git", "branch", "--set-upstream-to=" + upstream, branch})
|
self.RunCommand([]string{"git", "branch", "--set-upstream-to=" + upstream, branch})
|
||||||
|
|
||||||
|
@@ -315,6 +315,7 @@ var tests = []*components.IntegrationTest{
|
|||||||
ui.Accordion,
|
ui.Accordion,
|
||||||
ui.DoublePopup,
|
ui.DoublePopup,
|
||||||
ui.EmptyMenu,
|
ui.EmptyMenu,
|
||||||
|
ui.KeybindingSuggestionsWhenSwitchingRepos,
|
||||||
ui.ModeSpecificKeybindingSuggestions,
|
ui.ModeSpecificKeybindingSuggestions,
|
||||||
ui.OpenLinkFailure,
|
ui.OpenLinkFailure,
|
||||||
ui.RangeSelect,
|
ui.RangeSelect,
|
||||||
|
@@ -0,0 +1,42 @@
|
|||||||
|
package ui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
|
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
||||||
|
)
|
||||||
|
|
||||||
|
var KeybindingSuggestionsWhenSwitchingRepos = NewIntegrationTest(NewIntegrationTestArgs{
|
||||||
|
Description: "Show correct keybinding suggestions after switching between repos",
|
||||||
|
ExtraCmdArgs: []string{},
|
||||||
|
Skip: false,
|
||||||
|
SetupConfig: func(config *config.AppConfig) {
|
||||||
|
otherRepo, _ := filepath.Abs("../other")
|
||||||
|
config.AppState.RecentRepos = []string{otherRepo}
|
||||||
|
},
|
||||||
|
SetupRepo: func(shell *Shell) {
|
||||||
|
shell.CloneNonBare("other")
|
||||||
|
},
|
||||||
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
|
switchToRepo := func(repo string) {
|
||||||
|
t.GlobalPress(keys.Universal.OpenRecentRepos)
|
||||||
|
t.ExpectPopup().Menu().Title(Equals("Recent repositories")).
|
||||||
|
Lines(
|
||||||
|
Contains(repo).IsSelected(),
|
||||||
|
Contains("Cancel"),
|
||||||
|
).Confirm()
|
||||||
|
t.Views().Status().Content(Contains(repo + " → master"))
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Views().Files().Focus()
|
||||||
|
t.Views().Options().Content(
|
||||||
|
Equals("Commit: c | Stash: s | Reset: D | Keybindings: ? | Cancel: <esc>"))
|
||||||
|
|
||||||
|
switchToRepo("other")
|
||||||
|
switchToRepo("repo")
|
||||||
|
|
||||||
|
t.Views().Options().Content(
|
||||||
|
Equals("Commit: c | Stash: s | Reset: D | Keybindings: ? | Cancel: <esc>"))
|
||||||
|
},
|
||||||
|
})
|
Reference in New Issue
Block a user