mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-31 14:24:25 +03:00
Clear keybinding functions in resetHelpersAndControllers
When switching to a repo that was open before, the context tree is reused, so before adding keybinding functions to those contexts again, we need to clear the old ones.
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.
|
||||||
|
@ -37,9 +37,6 @@ var KeybindingSuggestionsWhenSwitchingRepos = NewIntegrationTest(NewIntegrationT
|
|||||||
switchToRepo("repo")
|
switchToRepo("repo")
|
||||||
|
|
||||||
t.Views().Options().Content(
|
t.Views().Options().Content(
|
||||||
/* EXPECTED:
|
|
||||||
Equals("Commit: c | Stash: s | Reset: D | Keybindings: ? | Cancel: <esc>"))
|
Equals("Commit: c | Stash: s | Reset: D | Keybindings: ? | Cancel: <esc>"))
|
||||||
ACTUAL (all keybindings appear twice): */
|
|
||||||
Equals("Commit: c | Stash: s | Reset: D | Commit: c | Stash: s | Reset: D | Keybindings: ? | Cancel: <esc> | Keybindings: ? | Cancel: <esc>"))
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user