mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 12:25:47 +02:00
refactor keybindings
This commit is contained in:
parent
2db4636815
commit
226985bf76
19 changed files with 215 additions and 201 deletions
|
@ -1,6 +1,8 @@
|
|||
package context
|
||||
|
||||
import "github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
)
|
||||
|
||||
type BaseContext struct {
|
||||
kind types.ContextKind
|
||||
|
@ -9,9 +11,14 @@ type BaseContext struct {
|
|||
windowName string
|
||||
onGetOptionsMap func() map[string]string
|
||||
|
||||
keybindingsFns []types.KeybindingsFn
|
||||
keybindings []*types.Binding
|
||||
|
||||
*ParentContextMgr
|
||||
}
|
||||
|
||||
var _ types.IBaseContext = &BaseContext{}
|
||||
|
||||
type NewBaseContextOpts struct {
|
||||
Kind types.ContextKind
|
||||
Key types.ContextKey
|
||||
|
@ -58,3 +65,18 @@ func (self *BaseContext) GetKind() types.ContextKind {
|
|||
func (self *BaseContext) GetKey() types.ContextKey {
|
||||
return self.key
|
||||
}
|
||||
|
||||
func (self *BaseContext) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
|
||||
bindings := []*types.Binding{}
|
||||
for i := range self.keybindingsFns {
|
||||
// the first binding in the bindings array takes precedence but we want the
|
||||
// last keybindingsFn to take precedence to we add them in reverse
|
||||
bindings = append(bindings, self.keybindingsFns[len(self.keybindingsFns)-1-i](opts)...)
|
||||
}
|
||||
|
||||
return bindings
|
||||
}
|
||||
|
||||
func (self *BaseContext) AddKeybindingsFn(fn types.KeybindingsFn) {
|
||||
self.keybindingsFns = append(self.keybindingsFns, fn)
|
||||
}
|
||||
|
|
|
@ -55,6 +55,8 @@ func NewCommitFilesContext(
|
|||
c: c,
|
||||
}
|
||||
|
||||
baseContext.AddKeybindingsFn(listContextTrait.keybindings)
|
||||
|
||||
self.BaseContext = baseContext
|
||||
self.ListContextTrait = listContextTrait
|
||||
self.CommitFileTreeViewModel = viewModel
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/jesseduffield/gocui"
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
)
|
||||
|
@ -182,32 +181,28 @@ func (self *ListContextTrait) HandleRenderToMain() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (self *ListContextTrait) Keybindings(
|
||||
getKey func(key string) interface{},
|
||||
config config.KeybindingConfig,
|
||||
guards types.KeybindingGuards,
|
||||
) []*types.Binding {
|
||||
func (self *ListContextTrait) keybindings(opts types.KeybindingsOpts) []*types.Binding {
|
||||
return []*types.Binding{
|
||||
{Tag: "navigation", Key: getKey(config.Universal.PrevItemAlt), Modifier: gocui.ModNone, Handler: self.HandlePrevLine},
|
||||
{Tag: "navigation", Key: getKey(config.Universal.PrevItem), Modifier: gocui.ModNone, Handler: self.HandlePrevLine},
|
||||
{Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.PrevItemAlt), Modifier: gocui.ModNone, Handler: self.HandlePrevLine},
|
||||
{Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.PrevItem), Modifier: gocui.ModNone, Handler: self.HandlePrevLine},
|
||||
{Tag: "navigation", Key: gocui.MouseWheelUp, Modifier: gocui.ModNone, Handler: self.HandlePrevLine},
|
||||
{Tag: "navigation", Key: getKey(config.Universal.NextItemAlt), Modifier: gocui.ModNone, Handler: self.HandleNextLine},
|
||||
{Tag: "navigation", Key: getKey(config.Universal.NextItem), Modifier: gocui.ModNone, Handler: self.HandleNextLine},
|
||||
{Tag: "navigation", Key: getKey(config.Universal.PrevPage), Modifier: gocui.ModNone, Handler: self.HandlePrevPage, Description: self.c.Tr.LcPrevPage},
|
||||
{Tag: "navigation", Key: getKey(config.Universal.NextPage), Modifier: gocui.ModNone, Handler: self.HandleNextPage, Description: self.c.Tr.LcNextPage},
|
||||
{Tag: "navigation", Key: getKey(config.Universal.GotoTop), Modifier: gocui.ModNone, Handler: self.HandleGotoTop, Description: self.c.Tr.LcGotoTop},
|
||||
{Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.NextItemAlt), Modifier: gocui.ModNone, Handler: self.HandleNextLine},
|
||||
{Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.NextItem), Modifier: gocui.ModNone, Handler: self.HandleNextLine},
|
||||
{Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.PrevPage), Modifier: gocui.ModNone, Handler: self.HandlePrevPage, Description: self.c.Tr.LcPrevPage},
|
||||
{Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.NextPage), Modifier: gocui.ModNone, Handler: self.HandleNextPage, Description: self.c.Tr.LcNextPage},
|
||||
{Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.GotoTop), Modifier: gocui.ModNone, Handler: self.HandleGotoTop, Description: self.c.Tr.LcGotoTop},
|
||||
{Key: gocui.MouseLeft, Modifier: gocui.ModNone, Handler: func() error { return self.HandleClick(nil) }},
|
||||
{Tag: "navigation", Key: gocui.MouseWheelDown, Modifier: gocui.ModNone, Handler: self.HandleNextLine},
|
||||
{Tag: "navigation", Key: getKey(config.Universal.ScrollLeft), Modifier: gocui.ModNone, Handler: self.HandleScrollLeft},
|
||||
{Tag: "navigation", Key: getKey(config.Universal.ScrollRight), Modifier: gocui.ModNone, Handler: self.HandleScrollRight},
|
||||
{Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.ScrollLeft), Modifier: gocui.ModNone, Handler: self.HandleScrollLeft},
|
||||
{Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.ScrollRight), Modifier: gocui.ModNone, Handler: self.HandleScrollRight},
|
||||
{
|
||||
Key: getKey(config.Universal.StartSearch),
|
||||
Key: opts.GetKey(opts.Config.Universal.StartSearch),
|
||||
Handler: func() error { self.c.OpenSearch(); return nil },
|
||||
Description: self.c.Tr.LcStartSearch,
|
||||
Tag: "navigation",
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Universal.GotoBottom),
|
||||
Key: opts.GetKey(opts.Config.Universal.GotoBottom),
|
||||
Description: self.c.Tr.LcGotoBottom,
|
||||
Handler: self.HandleGotoBottom,
|
||||
Tag: "navigation",
|
||||
|
|
|
@ -55,6 +55,8 @@ func NewTagsContext(
|
|||
c: c,
|
||||
}
|
||||
|
||||
baseContext.AddKeybindingsFn(listContextTrait.keybindings)
|
||||
|
||||
self.BaseContext = baseContext
|
||||
self.ListContextTrait = listContextTrait
|
||||
self.TagsViewModel = list
|
||||
|
|
|
@ -55,6 +55,8 @@ func NewWorkingTreeContext(
|
|||
c: c,
|
||||
}
|
||||
|
||||
baseContext.AddKeybindingsFn(listContextTrait.keybindings)
|
||||
|
||||
self.BaseContext = baseContext
|
||||
self.ListContextTrait = listContextTrait
|
||||
self.FileTreeViewModel = viewModel
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
)
|
||||
|
||||
|
@ -43,11 +42,11 @@ func NewBisectController(
|
|||
}
|
||||
}
|
||||
|
||||
func (self *BisectController) Keybindings(getKey func(key string) interface{}, config config.KeybindingConfig, guards types.KeybindingGuards) []*types.Binding {
|
||||
func (self *BisectController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
|
||||
bindings := []*types.Binding{
|
||||
{
|
||||
Key: getKey(config.Commits.ViewBisectOptions),
|
||||
Handler: guards.OutsideFilterMode(self.checkSelected(self.openMenu)),
|
||||
Key: opts.GetKey(opts.Config.Commits.ViewBisectOptions),
|
||||
Handler: opts.Guards.OutsideFilterMode(self.checkSelected(self.openMenu)),
|
||||
Description: self.c.Tr.LcViewBisectOptions,
|
||||
OpensMenu: true,
|
||||
},
|
||||
|
|
|
@ -87,10 +87,10 @@ func NewFilesController(
|
|||
}
|
||||
}
|
||||
|
||||
func (self *FilesController) Keybindings(getKey func(key string) interface{}, config config.KeybindingConfig, guards types.KeybindingGuards) []*types.Binding {
|
||||
bindings := []*types.Binding{
|
||||
func (self *FilesController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
|
||||
return []*types.Binding{
|
||||
{
|
||||
Key: getKey(config.Universal.Select),
|
||||
Key: opts.GetKey(opts.Config.Universal.Select),
|
||||
Handler: self.checkSelectedFileNode(self.press),
|
||||
Description: self.c.Tr.LcToggleStaged,
|
||||
},
|
||||
|
@ -99,103 +99,101 @@ func (self *FilesController) Keybindings(getKey func(key string) interface{}, co
|
|||
Handler: func() error { return self.context.HandleClick(self.checkSelectedFileNode(self.press)) },
|
||||
},
|
||||
{
|
||||
Key: getKey("<c-b>"), // TODO: softcode
|
||||
Key: opts.GetKey("<c-b>"), // TODO: softcode
|
||||
Handler: self.handleStatusFilterPressed,
|
||||
Description: self.c.Tr.LcFileFilter,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Files.CommitChanges),
|
||||
Key: opts.GetKey(opts.Config.Files.CommitChanges),
|
||||
Handler: self.HandleCommitPress,
|
||||
Description: self.c.Tr.CommitChanges,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Files.CommitChangesWithoutHook),
|
||||
Key: opts.GetKey(opts.Config.Files.CommitChangesWithoutHook),
|
||||
Handler: self.HandleWIPCommitPress,
|
||||
Description: self.c.Tr.LcCommitChangesWithoutHook,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Files.AmendLastCommit),
|
||||
Key: opts.GetKey(opts.Config.Files.AmendLastCommit),
|
||||
Handler: self.handleAmendCommitPress,
|
||||
Description: self.c.Tr.AmendLastCommit,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Files.CommitChangesWithEditor),
|
||||
Key: opts.GetKey(opts.Config.Files.CommitChangesWithEditor),
|
||||
Handler: self.HandleCommitEditorPress,
|
||||
Description: self.c.Tr.CommitChangesWithEditor,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Universal.Edit),
|
||||
Key: opts.GetKey(opts.Config.Universal.Edit),
|
||||
Handler: self.checkSelectedFileNode(self.edit),
|
||||
Description: self.c.Tr.LcEditFile,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Universal.OpenFile),
|
||||
Key: opts.GetKey(opts.Config.Universal.OpenFile),
|
||||
Handler: self.Open,
|
||||
Description: self.c.Tr.LcOpenFile,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Files.IgnoreFile),
|
||||
Key: opts.GetKey(opts.Config.Files.IgnoreFile),
|
||||
Handler: self.checkSelectedFileNode(self.ignore),
|
||||
Description: self.c.Tr.LcIgnoreFile,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Universal.Remove),
|
||||
Key: opts.GetKey(opts.Config.Universal.Remove),
|
||||
Handler: self.checkSelectedFileNode(self.remove),
|
||||
Description: self.c.Tr.LcViewDiscardOptions,
|
||||
OpensMenu: true,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Files.RefreshFiles),
|
||||
Key: opts.GetKey(opts.Config.Files.RefreshFiles),
|
||||
Handler: self.refresh,
|
||||
Description: self.c.Tr.LcRefreshFiles,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Files.StashAllChanges),
|
||||
Key: opts.GetKey(opts.Config.Files.StashAllChanges),
|
||||
Handler: self.stash,
|
||||
Description: self.c.Tr.LcStashAllChanges,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Files.ViewStashOptions),
|
||||
Key: opts.GetKey(opts.Config.Files.ViewStashOptions),
|
||||
Handler: self.createStashMenu,
|
||||
Description: self.c.Tr.LcViewStashOptions,
|
||||
OpensMenu: true,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Files.ToggleStagedAll),
|
||||
Key: opts.GetKey(opts.Config.Files.ToggleStagedAll),
|
||||
Handler: self.stageAll,
|
||||
Description: self.c.Tr.LcToggleStagedAll,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Universal.GoInto),
|
||||
Key: opts.GetKey(opts.Config.Universal.GoInto),
|
||||
Handler: self.enter,
|
||||
Description: self.c.Tr.FileEnter,
|
||||
},
|
||||
{
|
||||
ViewName: "",
|
||||
Key: getKey(config.Universal.ExecuteCustomCommand),
|
||||
Key: opts.GetKey(opts.Config.Universal.ExecuteCustomCommand),
|
||||
Handler: self.handleCustomCommand,
|
||||
Description: self.c.Tr.LcExecuteCustomCommand,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Commits.ViewResetOptions),
|
||||
Key: opts.GetKey(opts.Config.Commits.ViewResetOptions),
|
||||
Handler: self.createResetMenu,
|
||||
Description: self.c.Tr.LcViewResetToUpstreamOptions,
|
||||
OpensMenu: true,
|
||||
},
|
||||
// here
|
||||
{
|
||||
Key: getKey(config.Files.ToggleTreeView),
|
||||
Key: opts.GetKey(opts.Config.Files.ToggleTreeView),
|
||||
Handler: self.toggleTreeView,
|
||||
Description: self.c.Tr.LcToggleTreeView,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Files.OpenMergeTool),
|
||||
Key: opts.GetKey(opts.Config.Files.OpenMergeTool),
|
||||
Handler: self.OpenMergeTool,
|
||||
Description: self.c.Tr.LcOpenMergeTool,
|
||||
},
|
||||
}
|
||||
|
||||
return append(bindings, self.context.Keybindings(getKey, config, guards)...)
|
||||
}
|
||||
|
||||
func (self *FilesController) press(node *filetree.FileNode) error {
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"github.com/jesseduffield/lazygit/pkg/commands/hosting_service"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
)
|
||||
|
@ -91,108 +90,104 @@ func NewLocalCommitsController(
|
|||
}
|
||||
}
|
||||
|
||||
func (self *LocalCommitsController) Keybindings(
|
||||
getKey func(key string) interface{},
|
||||
config config.KeybindingConfig,
|
||||
guards types.KeybindingGuards,
|
||||
) []*types.Binding {
|
||||
func (self *LocalCommitsController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
|
||||
outsideFilterModeBindings := []*types.Binding{
|
||||
{
|
||||
Key: getKey(config.Commits.SquashDown),
|
||||
Key: opts.GetKey(opts.Config.Commits.SquashDown),
|
||||
Handler: self.squashDown,
|
||||
Description: self.c.Tr.LcSquashDown,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Commits.MarkCommitAsFixup),
|
||||
Key: opts.GetKey(opts.Config.Commits.MarkCommitAsFixup),
|
||||
Handler: self.fixup,
|
||||
Description: self.c.Tr.LcFixupCommit,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Commits.RenameCommit),
|
||||
Key: opts.GetKey(opts.Config.Commits.RenameCommit),
|
||||
Handler: self.checkSelected(self.reword),
|
||||
Description: self.c.Tr.LcRewordCommit,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Commits.RenameCommitWithEditor),
|
||||
Key: opts.GetKey(opts.Config.Commits.RenameCommitWithEditor),
|
||||
Handler: self.rewordEditor,
|
||||
Description: self.c.Tr.LcRenameCommitEditor,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Universal.Remove),
|
||||
Key: opts.GetKey(opts.Config.Universal.Remove),
|
||||
Handler: self.drop,
|
||||
Description: self.c.Tr.LcDeleteCommit,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Universal.Edit),
|
||||
Key: opts.GetKey(opts.Config.Universal.Edit),
|
||||
Handler: self.edit,
|
||||
Description: self.c.Tr.LcEditCommit,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Commits.PickCommit),
|
||||
Key: opts.GetKey(opts.Config.Commits.PickCommit),
|
||||
Handler: self.pick,
|
||||
Description: self.c.Tr.LcPickCommit,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Commits.CreateFixupCommit),
|
||||
Key: opts.GetKey(opts.Config.Commits.CreateFixupCommit),
|
||||
Handler: self.checkSelected(self.handleCreateFixupCommit),
|
||||
Description: self.c.Tr.LcCreateFixupCommit,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Commits.SquashAboveCommits),
|
||||
Key: opts.GetKey(opts.Config.Commits.SquashAboveCommits),
|
||||
Handler: self.checkSelected(self.handleSquashAllAboveFixupCommits),
|
||||
Description: self.c.Tr.LcSquashAboveCommits,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Commits.MoveDownCommit),
|
||||
Key: opts.GetKey(opts.Config.Commits.MoveDownCommit),
|
||||
Handler: self.handleCommitMoveDown,
|
||||
Description: self.c.Tr.LcMoveDownCommit,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Commits.MoveUpCommit),
|
||||
Key: opts.GetKey(opts.Config.Commits.MoveUpCommit),
|
||||
Handler: self.handleCommitMoveUp,
|
||||
Description: self.c.Tr.LcMoveUpCommit,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Commits.AmendToCommit),
|
||||
Key: opts.GetKey(opts.Config.Commits.AmendToCommit),
|
||||
Handler: self.handleCommitAmendTo,
|
||||
Description: self.c.Tr.LcAmendToCommit,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Commits.RevertCommit),
|
||||
Key: opts.GetKey(opts.Config.Commits.RevertCommit),
|
||||
Handler: self.checkSelected(self.handleCommitRevert),
|
||||
Description: self.c.Tr.LcRevertCommit,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Universal.New),
|
||||
Key: opts.GetKey(opts.Config.Universal.New),
|
||||
Modifier: gocui.ModNone,
|
||||
Handler: self.checkSelected(self.newBranch),
|
||||
Description: self.c.Tr.LcCreateNewBranchFromCommit,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Commits.CherryPickCopy),
|
||||
Key: opts.GetKey(opts.Config.Commits.CherryPickCopy),
|
||||
Handler: self.checkSelected(self.copy),
|
||||
Description: self.c.Tr.LcCherryPickCopy,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Commits.CherryPickCopyRange),
|
||||
Key: opts.GetKey(opts.Config.Commits.CherryPickCopyRange),
|
||||
Handler: self.checkSelected(self.copyRange),
|
||||
Description: self.c.Tr.LcCherryPickCopyRange,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Commits.PasteCommits),
|
||||
Handler: guards.OutsideFilterMode(self.paste),
|
||||
Key: opts.GetKey(opts.Config.Commits.PasteCommits),
|
||||
Handler: opts.Guards.OutsideFilterMode(self.paste),
|
||||
Description: self.c.Tr.LcPasteCommits,
|
||||
},
|
||||
// overriding these navigation keybindings because we might need to load
|
||||
// more commits on demand
|
||||
{
|
||||
Key: getKey(config.Universal.StartSearch),
|
||||
Key: opts.GetKey(opts.Config.Universal.StartSearch),
|
||||
Handler: self.openSearch,
|
||||
Description: self.c.Tr.LcStartSearch,
|
||||
Tag: "navigation",
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Universal.GotoBottom),
|
||||
Key: opts.GetKey(opts.Config.Universal.GotoBottom),
|
||||
Handler: self.gotoBottom,
|
||||
Description: self.c.Tr.LcGotoBottom,
|
||||
Tag: "navigation",
|
||||
|
@ -204,49 +199,49 @@ func (self *LocalCommitsController) Keybindings(
|
|||
}
|
||||
|
||||
for _, binding := range outsideFilterModeBindings {
|
||||
binding.Handler = guards.OutsideFilterMode(binding.Handler)
|
||||
binding.Handler = opts.Guards.OutsideFilterMode(binding.Handler)
|
||||
}
|
||||
|
||||
bindings := append(outsideFilterModeBindings, []*types.Binding{
|
||||
{
|
||||
Key: getKey(config.Commits.OpenLogMenu),
|
||||
Key: opts.GetKey(opts.Config.Commits.OpenLogMenu),
|
||||
Handler: self.handleOpenLogMenu,
|
||||
Description: self.c.Tr.LcOpenLogMenu,
|
||||
OpensMenu: true,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Commits.ViewResetOptions),
|
||||
Key: opts.GetKey(opts.Config.Commits.ViewResetOptions),
|
||||
Handler: self.checkSelected(self.handleCreateCommitResetMenu),
|
||||
Description: self.c.Tr.LcResetToThisCommit,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Universal.GoInto),
|
||||
Key: opts.GetKey(opts.Config.Universal.GoInto),
|
||||
Handler: self.checkSelected(self.enter),
|
||||
Description: self.c.Tr.LcViewCommitFiles,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Commits.CheckoutCommit),
|
||||
Key: opts.GetKey(opts.Config.Commits.CheckoutCommit),
|
||||
Handler: self.checkSelected(self.handleCheckoutCommit),
|
||||
Description: self.c.Tr.LcCheckoutCommit,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Commits.TagCommit),
|
||||
Key: opts.GetKey(opts.Config.Commits.TagCommit),
|
||||
Handler: self.checkSelected(self.handleTagCommit),
|
||||
Description: self.c.Tr.LcTagCommit,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Commits.CopyCommitMessageToClipboard),
|
||||
Key: opts.GetKey(opts.Config.Commits.CopyCommitMessageToClipboard),
|
||||
Handler: self.checkSelected(self.handleCopySelectedCommitMessageToClipboard),
|
||||
Description: self.c.Tr.LcCopyCommitMessageToClipboard,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Commits.OpenInBrowser),
|
||||
Key: opts.GetKey(opts.Config.Commits.OpenInBrowser),
|
||||
Handler: self.checkSelected(self.handleOpenCommitInBrowser),
|
||||
Description: self.c.Tr.LcOpenCommitInBrowser,
|
||||
},
|
||||
}...)
|
||||
|
||||
return append(bindings, self.context.Keybindings(getKey, config, guards)...)
|
||||
return bindings
|
||||
}
|
||||
|
||||
func (self *LocalCommitsController) squashDown() error {
|
||||
|
|
|
@ -2,7 +2,6 @@ package controllers
|
|||
|
||||
import (
|
||||
"github.com/jesseduffield/gocui"
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
)
|
||||
|
||||
|
@ -27,18 +26,18 @@ func NewMenuController(
|
|||
}
|
||||
}
|
||||
|
||||
func (self *MenuController) Keybindings(getKey func(key string) interface{}, config config.KeybindingConfig, guards types.KeybindingGuards) []*types.Binding {
|
||||
func (self *MenuController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
|
||||
bindings := []*types.Binding{
|
||||
{
|
||||
Key: getKey(config.Universal.Select),
|
||||
Key: opts.GetKey(opts.Config.Universal.Select),
|
||||
Handler: self.press,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Universal.Confirm),
|
||||
Key: opts.GetKey(opts.Config.Universal.Confirm),
|
||||
Handler: self.press,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Universal.ConfirmAlt1),
|
||||
Key: opts.GetKey(opts.Config.Universal.ConfirmAlt1),
|
||||
Handler: self.press,
|
||||
},
|
||||
{
|
||||
|
@ -47,7 +46,7 @@ func (self *MenuController) Keybindings(getKey func(key string) interface{}, con
|
|||
},
|
||||
}
|
||||
|
||||
return append(bindings, self.context.Keybindings(getKey, config, guards)...)
|
||||
return bindings
|
||||
}
|
||||
|
||||
func (self *MenuController) press() error {
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"github.com/jesseduffield/gocui"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
|
@ -40,10 +39,10 @@ func NewRemotesController(
|
|||
}
|
||||
}
|
||||
|
||||
func (self *RemotesController) Keybindings(getKey func(key string) interface{}, config config.KeybindingConfig, guards types.KeybindingGuards) []*types.Binding {
|
||||
func (self *RemotesController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
|
||||
bindings := []*types.Binding{
|
||||
{
|
||||
Key: getKey(config.Universal.GoInto),
|
||||
Key: opts.GetKey(opts.Config.Universal.GoInto),
|
||||
Handler: self.checkSelected(self.enter),
|
||||
},
|
||||
{
|
||||
|
@ -51,28 +50,28 @@ func (self *RemotesController) Keybindings(getKey func(key string) interface{},
|
|||
Handler: func() error { return self.context.HandleClick(self.checkSelected(self.enter)) },
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Branches.FetchRemote),
|
||||
Key: opts.GetKey(opts.Config.Branches.FetchRemote),
|
||||
Handler: self.checkSelected(self.fetch),
|
||||
Description: self.c.Tr.LcFetchRemote,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Universal.New),
|
||||
Key: opts.GetKey(opts.Config.Universal.New),
|
||||
Handler: self.add,
|
||||
Description: self.c.Tr.LcAddNewRemote,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Universal.Remove),
|
||||
Key: opts.GetKey(opts.Config.Universal.Remove),
|
||||
Handler: self.checkSelected(self.remove),
|
||||
Description: self.c.Tr.LcRemoveRemote,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Universal.Edit),
|
||||
Key: opts.GetKey(opts.Config.Universal.Edit),
|
||||
Handler: self.checkSelected(self.edit),
|
||||
Description: self.c.Tr.LcEditRemote,
|
||||
},
|
||||
}
|
||||
|
||||
return append(bindings, self.context.Keybindings(getKey, config, guards)...)
|
||||
return bindings
|
||||
}
|
||||
|
||||
func (self *RemotesController) enter(remote *models.Remote) error {
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"github.com/jesseduffield/gocui"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
)
|
||||
|
@ -40,40 +39,40 @@ func NewSubmodulesController(
|
|||
}
|
||||
}
|
||||
|
||||
func (self *SubmodulesController) Keybindings(getKey func(key string) interface{}, config config.KeybindingConfig, guards types.KeybindingGuards) []*types.Binding {
|
||||
bindings := []*types.Binding{
|
||||
func (self *SubmodulesController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
|
||||
return []*types.Binding{
|
||||
{
|
||||
Key: getKey(config.Universal.GoInto),
|
||||
Key: opts.GetKey(opts.Config.Universal.GoInto),
|
||||
Handler: self.checkSelected(self.enter),
|
||||
Description: self.c.Tr.LcEnterSubmodule,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Universal.Remove),
|
||||
Key: opts.GetKey(opts.Config.Universal.Remove),
|
||||
Handler: self.checkSelected(self.remove),
|
||||
Description: self.c.Tr.LcRemoveSubmodule,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Submodules.Update),
|
||||
Key: opts.GetKey(opts.Config.Submodules.Update),
|
||||
Handler: self.checkSelected(self.update),
|
||||
Description: self.c.Tr.LcSubmoduleUpdate,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Universal.New),
|
||||
Key: opts.GetKey(opts.Config.Universal.New),
|
||||
Handler: self.add,
|
||||
Description: self.c.Tr.LcAddSubmodule,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Universal.Edit),
|
||||
Key: opts.GetKey(opts.Config.Universal.Edit),
|
||||
Handler: self.checkSelected(self.editURL),
|
||||
Description: self.c.Tr.LcEditSubmoduleUrl,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Submodules.Init),
|
||||
Key: opts.GetKey(opts.Config.Submodules.Init),
|
||||
Handler: self.checkSelected(self.init),
|
||||
Description: self.c.Tr.LcInitSubmodule,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Submodules.BulkMenu),
|
||||
Key: opts.GetKey(opts.Config.Submodules.BulkMenu),
|
||||
Handler: self.openBulkActionsMenu,
|
||||
Description: self.c.Tr.LcViewBulkSubmoduleOptions,
|
||||
OpensMenu: true,
|
||||
|
@ -83,8 +82,6 @@ func (self *SubmodulesController) Keybindings(getKey func(key string) interface{
|
|||
Handler: func() error { return self.context.HandleClick(self.checkSelected(self.enter)) },
|
||||
},
|
||||
}
|
||||
|
||||
return append(bindings, self.context.Keybindings(getKey, config, guards)...)
|
||||
}
|
||||
|
||||
func (self *SubmodulesController) enter(submodule *models.SubmoduleConfig) error {
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
)
|
||||
|
||||
|
@ -46,16 +45,16 @@ func NewSyncController(
|
|||
}
|
||||
}
|
||||
|
||||
func (self *SyncController) Keybindings(getKey func(key string) interface{}, config config.KeybindingConfig, guards types.KeybindingGuards) []*types.Binding {
|
||||
func (self *SyncController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
|
||||
bindings := []*types.Binding{
|
||||
{
|
||||
Key: getKey(config.Universal.PushFiles),
|
||||
Handler: guards.NoPopupPanel(self.HandlePush),
|
||||
Key: opts.GetKey(opts.Config.Universal.PushFiles),
|
||||
Handler: opts.Guards.NoPopupPanel(self.HandlePush),
|
||||
Description: self.c.Tr.LcPush,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Universal.PullFiles),
|
||||
Handler: guards.NoPopupPanel(self.HandlePull),
|
||||
Key: opts.GetKey(opts.Config.Universal.PullFiles),
|
||||
Handler: opts.Guards.NoPopupPanel(self.HandlePull),
|
||||
Description: self.c.Tr.LcPull,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package controllers
|
|||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
|
@ -48,42 +47,42 @@ func NewTagsController(
|
|||
}
|
||||
}
|
||||
|
||||
func (self *TagsController) Keybindings(getKey func(key string) interface{}, config config.KeybindingConfig, guards types.KeybindingGuards) []*types.Binding {
|
||||
func (self *TagsController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
|
||||
bindings := []*types.Binding{
|
||||
{
|
||||
Key: getKey(config.Universal.Select),
|
||||
Key: opts.GetKey(opts.Config.Universal.Select),
|
||||
Handler: self.withSelectedTag(self.checkout),
|
||||
Description: self.c.Tr.LcCheckout,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Universal.Remove),
|
||||
Key: opts.GetKey(opts.Config.Universal.Remove),
|
||||
Handler: self.withSelectedTag(self.delete),
|
||||
Description: self.c.Tr.LcDeleteTag,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Branches.PushTag),
|
||||
Key: opts.GetKey(opts.Config.Branches.PushTag),
|
||||
Handler: self.withSelectedTag(self.push),
|
||||
Description: self.c.Tr.LcPushTag,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Universal.New),
|
||||
Key: opts.GetKey(opts.Config.Universal.New),
|
||||
Handler: self.create,
|
||||
Description: self.c.Tr.LcCreateTag,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Commits.ViewResetOptions),
|
||||
Key: opts.GetKey(opts.Config.Commits.ViewResetOptions),
|
||||
Handler: self.withSelectedTag(self.createResetMenu),
|
||||
Description: self.c.Tr.LcViewResetOptions,
|
||||
OpensMenu: true,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Universal.GoInto),
|
||||
Key: opts.GetKey(opts.Config.Universal.GoInto),
|
||||
Handler: self.withSelectedTag(self.enter),
|
||||
Description: self.c.Tr.LcViewCommits,
|
||||
},
|
||||
}
|
||||
|
||||
return append(bindings, self.context.Keybindings(getKey, config, guards)...)
|
||||
return bindings
|
||||
}
|
||||
|
||||
func (self *TagsController) checkout(tag *models.Tag) error {
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
)
|
||||
|
@ -64,19 +63,15 @@ type reflogAction struct {
|
|||
to string
|
||||
}
|
||||
|
||||
func (self *UndoController) Keybindings(
|
||||
getKey func(key string) interface{},
|
||||
config config.KeybindingConfig,
|
||||
guards types.KeybindingGuards,
|
||||
) []*types.Binding {
|
||||
func (self *UndoController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
|
||||
bindings := []*types.Binding{
|
||||
{
|
||||
Key: getKey(config.Universal.Undo),
|
||||
Key: opts.GetKey(opts.Config.Universal.Undo),
|
||||
Handler: self.reflogUndo,
|
||||
Description: self.c.Tr.LcUndoReflog,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Universal.Redo),
|
||||
Key: opts.GetKey(opts.Config.Universal.Redo),
|
||||
Handler: self.reflogRedo,
|
||||
Description: self.c.Tr.LcRedoReflog,
|
||||
},
|
||||
|
|
|
@ -581,14 +581,16 @@ func (gui *Gui) resetControllers() {
|
|||
gui.helpers.Rebase.CheckMergeOrRebase,
|
||||
)
|
||||
|
||||
submodulesController := controllers.NewSubmodulesController(
|
||||
controllerCommon,
|
||||
gui.State.Contexts.Submodules,
|
||||
gui.git,
|
||||
gui.enterSubmodule,
|
||||
gui.getSelectedSubmodule,
|
||||
)
|
||||
|
||||
gui.Controllers = Controllers{
|
||||
Submodules: controllers.NewSubmodulesController(
|
||||
controllerCommon,
|
||||
gui.State.Contexts.Submodules,
|
||||
gui.git,
|
||||
gui.enterSubmodule,
|
||||
gui.getSelectedSubmodule,
|
||||
),
|
||||
Submodules: submodulesController,
|
||||
Files: controllers.NewFilesController(
|
||||
controllerCommon,
|
||||
gui.State.Contexts.Files,
|
||||
|
@ -670,6 +672,17 @@ func (gui *Gui) resetControllers() {
|
|||
),
|
||||
Sync: syncController,
|
||||
}
|
||||
|
||||
gui.State.Contexts.Submodules.AddKeybindingsFn(gui.Controllers.Submodules.GetKeybindings)
|
||||
gui.State.Contexts.Files.AddKeybindingsFn(gui.Controllers.Files.GetKeybindings)
|
||||
gui.State.Contexts.Tags.AddKeybindingsFn(gui.Controllers.Tags.GetKeybindings)
|
||||
// TODO: commit to one name here: local commits or branch commits
|
||||
gui.State.Contexts.BranchCommits.AddKeybindingsFn(gui.Controllers.LocalCommits.GetKeybindings)
|
||||
gui.State.Contexts.BranchCommits.AddKeybindingsFn(gui.Controllers.Bisect.GetKeybindings)
|
||||
gui.State.Contexts.Remotes.AddKeybindingsFn(gui.Controllers.Remotes.GetKeybindings)
|
||||
gui.State.Contexts.Menu.AddKeybindingsFn(gui.Controllers.Menu.GetKeybindings)
|
||||
gui.State.Contexts.Menu.AddKeybindingsFn(gui.Controllers.Menu.GetKeybindings)
|
||||
// TODO: handle global contexts
|
||||
}
|
||||
|
||||
var RuneReplacements = map[rune]string{
|
||||
|
|
|
@ -1355,16 +1355,16 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
|
|||
},
|
||||
}
|
||||
|
||||
keybindingsOpts := types.KeybindingsOpts{
|
||||
GetKey: gui.getKey,
|
||||
Config: config,
|
||||
Guards: guards,
|
||||
}
|
||||
|
||||
// global bindings
|
||||
for _, controller := range []types.IController{
|
||||
gui.Controllers.LocalCommits,
|
||||
gui.Controllers.Submodules,
|
||||
gui.Controllers.Files,
|
||||
gui.Controllers.Remotes,
|
||||
gui.Controllers.Menu,
|
||||
gui.Controllers.Bisect,
|
||||
gui.Controllers.Undo,
|
||||
gui.Controllers.Sync,
|
||||
gui.Controllers.Tags,
|
||||
gui.Controllers.Undo,
|
||||
} {
|
||||
context := controller.Context()
|
||||
viewName := ""
|
||||
|
@ -1375,27 +1375,17 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
|
|||
contextKeys = []string{string(context.GetKey())}
|
||||
}
|
||||
|
||||
for _, binding := range controller.Keybindings(gui.getKey, config, guards) {
|
||||
for _, binding := range controller.GetKeybindings(keybindingsOpts) {
|
||||
binding.Contexts = contextKeys
|
||||
binding.ViewName = viewName
|
||||
bindings = append(bindings, binding)
|
||||
}
|
||||
}
|
||||
|
||||
// while migrating we'll continue providing keybindings from the list contexts themselves.
|
||||
// for each controller we add above we need to remove the corresponding list context from here.
|
||||
for _, listContext := range []types.IListContext{
|
||||
gui.State.Contexts.Branches,
|
||||
gui.State.Contexts.RemoteBranches,
|
||||
gui.State.Contexts.ReflogCommits,
|
||||
gui.State.Contexts.SubCommits,
|
||||
gui.State.Contexts.Stash,
|
||||
gui.State.Contexts.CommitFiles,
|
||||
gui.State.Contexts.Suggestions,
|
||||
} {
|
||||
viewName := listContext.GetViewName()
|
||||
contextKey := listContext.GetKey()
|
||||
for _, binding := range listContext.Keybindings(gui.getKey, config, guards) {
|
||||
for _, context := range gui.allContexts() {
|
||||
viewName := context.GetViewName()
|
||||
contextKey := context.GetKey()
|
||||
for _, binding := range context.GetKeybindings(keybindingsOpts) {
|
||||
binding.Contexts = []string{string(contextKey)}
|
||||
binding.ViewName = viewName
|
||||
bindings = append(bindings, binding)
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/jesseduffield/gocui"
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
)
|
||||
|
@ -232,32 +231,34 @@ func (self *ListContext) HandleRenderToMain() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (self *ListContext) Keybindings(
|
||||
getKey func(key string) interface{},
|
||||
config config.KeybindingConfig,
|
||||
guards types.KeybindingGuards,
|
||||
) []*types.Binding {
|
||||
func (self *ListContext) attachKeybindings() *ListContext {
|
||||
self.BaseContext.AddKeybindingsFn(self.keybindings)
|
||||
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *ListContext) keybindings(opts types.KeybindingsOpts) []*types.Binding {
|
||||
return []*types.Binding{
|
||||
{Tag: "navigation", Key: getKey(config.Universal.PrevItemAlt), Modifier: gocui.ModNone, Handler: self.HandlePrevLine},
|
||||
{Tag: "navigation", Key: getKey(config.Universal.PrevItem), Modifier: gocui.ModNone, Handler: self.HandlePrevLine},
|
||||
{Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.PrevItemAlt), Modifier: gocui.ModNone, Handler: self.HandlePrevLine},
|
||||
{Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.PrevItem), Modifier: gocui.ModNone, Handler: self.HandlePrevLine},
|
||||
{Tag: "navigation", Key: gocui.MouseWheelUp, Modifier: gocui.ModNone, Handler: self.HandlePrevLine},
|
||||
{Tag: "navigation", Key: getKey(config.Universal.NextItemAlt), Modifier: gocui.ModNone, Handler: self.HandleNextLine},
|
||||
{Tag: "navigation", Key: getKey(config.Universal.NextItem), Modifier: gocui.ModNone, Handler: self.HandleNextLine},
|
||||
{Tag: "navigation", Key: getKey(config.Universal.PrevPage), Modifier: gocui.ModNone, Handler: self.HandlePrevPage, Description: self.Gui.c.Tr.LcPrevPage},
|
||||
{Tag: "navigation", Key: getKey(config.Universal.NextPage), Modifier: gocui.ModNone, Handler: self.HandleNextPage, Description: self.Gui.c.Tr.LcNextPage},
|
||||
{Tag: "navigation", Key: getKey(config.Universal.GotoTop), Modifier: gocui.ModNone, Handler: self.HandleGotoTop, Description: self.Gui.c.Tr.LcGotoTop},
|
||||
{Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.NextItemAlt), Modifier: gocui.ModNone, Handler: self.HandleNextLine},
|
||||
{Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.NextItem), Modifier: gocui.ModNone, Handler: self.HandleNextLine},
|
||||
{Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.PrevPage), Modifier: gocui.ModNone, Handler: self.HandlePrevPage, Description: self.Gui.c.Tr.LcPrevPage},
|
||||
{Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.NextPage), Modifier: gocui.ModNone, Handler: self.HandleNextPage, Description: self.Gui.c.Tr.LcNextPage},
|
||||
{Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.GotoTop), Modifier: gocui.ModNone, Handler: self.HandleGotoTop, Description: self.Gui.c.Tr.LcGotoTop},
|
||||
{Key: gocui.MouseLeft, Modifier: gocui.ModNone, Handler: func() error { return self.HandleClick(nil) }},
|
||||
{Tag: "navigation", Key: gocui.MouseWheelDown, Modifier: gocui.ModNone, Handler: self.HandleNextLine},
|
||||
{Tag: "navigation", Key: getKey(config.Universal.ScrollLeft), Modifier: gocui.ModNone, Handler: self.HandleScrollLeft},
|
||||
{Tag: "navigation", Key: getKey(config.Universal.ScrollRight), Modifier: gocui.ModNone, Handler: self.HandleScrollRight},
|
||||
{Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.ScrollLeft), Modifier: gocui.ModNone, Handler: self.HandleScrollLeft},
|
||||
{Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.ScrollRight), Modifier: gocui.ModNone, Handler: self.HandleScrollRight},
|
||||
{
|
||||
Key: getKey(config.Universal.StartSearch),
|
||||
Key: opts.GetKey(opts.Config.Universal.StartSearch),
|
||||
Handler: func() error { return self.Gui.handleOpenSearch(self.GetViewName()) },
|
||||
Description: self.Gui.c.Tr.LcStartSearch,
|
||||
Tag: "navigation",
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Universal.GotoBottom),
|
||||
Key: opts.GetKey(opts.Config.Universal.GotoBottom),
|
||||
Description: self.Gui.c.Tr.LcGotoBottom,
|
||||
Handler: self.HandleGotoBottom,
|
||||
Tag: "navigation",
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
)
|
||||
|
||||
func (gui *Gui) menuListContext() types.IListContext {
|
||||
return &ListContext{
|
||||
return (&ListContext{
|
||||
BaseContext: context.NewBaseContext(context.NewBaseContextOpts{
|
||||
ViewName: "menu",
|
||||
Key: "menu",
|
||||
|
@ -25,7 +25,7 @@ func (gui *Gui) menuListContext() types.IListContext {
|
|||
Gui: gui,
|
||||
|
||||
// no GetDisplayStrings field because we do a custom render on menu creation
|
||||
}
|
||||
}).attachKeybindings()
|
||||
}
|
||||
|
||||
func (gui *Gui) filesListContext() *context.WorkingTreeContext {
|
||||
|
@ -49,7 +49,7 @@ func (gui *Gui) filesListContext() *context.WorkingTreeContext {
|
|||
}
|
||||
|
||||
func (gui *Gui) branchesListContext() types.IListContext {
|
||||
return &ListContext{
|
||||
return (&ListContext{
|
||||
BaseContext: context.NewBaseContext(context.NewBaseContextOpts{
|
||||
ViewName: "branches",
|
||||
WindowName: "branches",
|
||||
|
@ -70,11 +70,11 @@ func (gui *Gui) branchesListContext() types.IListContext {
|
|||
}
|
||||
return item.ID()
|
||||
},
|
||||
}
|
||||
}).attachKeybindings()
|
||||
}
|
||||
|
||||
func (gui *Gui) remotesListContext() types.IListContext {
|
||||
return &ListContext{
|
||||
return (&ListContext{
|
||||
BaseContext: context.NewBaseContext(context.NewBaseContextOpts{
|
||||
ViewName: "branches",
|
||||
WindowName: "branches",
|
||||
|
@ -95,11 +95,11 @@ func (gui *Gui) remotesListContext() types.IListContext {
|
|||
}
|
||||
return item.ID()
|
||||
},
|
||||
}
|
||||
}).attachKeybindings()
|
||||
}
|
||||
|
||||
func (gui *Gui) remoteBranchesListContext() types.IListContext {
|
||||
return &ListContext{
|
||||
return (&ListContext{
|
||||
BaseContext: context.NewBaseContext(context.NewBaseContextOpts{
|
||||
ViewName: "branches",
|
||||
WindowName: "branches",
|
||||
|
@ -120,7 +120,7 @@ func (gui *Gui) remoteBranchesListContext() types.IListContext {
|
|||
}
|
||||
return item.ID()
|
||||
},
|
||||
}
|
||||
}).attachKeybindings()
|
||||
}
|
||||
|
||||
func (gui *Gui) withDiffModeCheck(f func() error) func() error {
|
||||
|
@ -149,7 +149,7 @@ func (gui *Gui) tagsListContext() *context.TagsContext {
|
|||
|
||||
func (gui *Gui) branchCommitsListContext() types.IListContext {
|
||||
parseEmoji := gui.c.UserConfig.Git.ParseEmoji
|
||||
return &ListContext{
|
||||
return (&ListContext{
|
||||
BaseContext: context.NewBaseContext(context.NewBaseContextOpts{
|
||||
ViewName: "commits",
|
||||
WindowName: "commits",
|
||||
|
@ -190,12 +190,12 @@ func (gui *Gui) branchCommitsListContext() types.IListContext {
|
|||
return item.ID()
|
||||
},
|
||||
RenderSelection: true,
|
||||
}
|
||||
}).attachKeybindings()
|
||||
}
|
||||
|
||||
func (gui *Gui) subCommitsListContext() types.IListContext {
|
||||
parseEmoji := gui.c.UserConfig.Git.ParseEmoji
|
||||
return &ListContext{
|
||||
return (&ListContext{
|
||||
BaseContext: context.NewBaseContext(context.NewBaseContextOpts{
|
||||
ViewName: "branches",
|
||||
WindowName: "branches",
|
||||
|
@ -235,7 +235,7 @@ func (gui *Gui) subCommitsListContext() types.IListContext {
|
|||
return item.ID()
|
||||
},
|
||||
RenderSelection: true,
|
||||
}
|
||||
}).attachKeybindings()
|
||||
}
|
||||
|
||||
func (gui *Gui) shouldShowGraph() bool {
|
||||
|
@ -259,7 +259,7 @@ func (gui *Gui) shouldShowGraph() bool {
|
|||
|
||||
func (gui *Gui) reflogCommitsListContext() types.IListContext {
|
||||
parseEmoji := gui.c.UserConfig.Git.ParseEmoji
|
||||
return &ListContext{
|
||||
return (&ListContext{
|
||||
BaseContext: context.NewBaseContext(context.NewBaseContextOpts{
|
||||
ViewName: "commits",
|
||||
WindowName: "commits",
|
||||
|
@ -286,11 +286,11 @@ func (gui *Gui) reflogCommitsListContext() types.IListContext {
|
|||
}
|
||||
return item.ID()
|
||||
},
|
||||
}
|
||||
}).attachKeybindings()
|
||||
}
|
||||
|
||||
func (gui *Gui) stashListContext() types.IListContext {
|
||||
return &ListContext{
|
||||
return (&ListContext{
|
||||
BaseContext: context.NewBaseContext(context.NewBaseContextOpts{
|
||||
ViewName: "stash",
|
||||
WindowName: "stash",
|
||||
|
@ -311,7 +311,7 @@ func (gui *Gui) stashListContext() types.IListContext {
|
|||
}
|
||||
return item.ID()
|
||||
},
|
||||
}
|
||||
}).attachKeybindings()
|
||||
}
|
||||
|
||||
func (gui *Gui) commitFilesListContext() *context.CommitFilesContext {
|
||||
|
@ -339,7 +339,7 @@ func (gui *Gui) commitFilesListContext() *context.CommitFilesContext {
|
|||
}
|
||||
|
||||
func (gui *Gui) submodulesListContext() types.IListContext {
|
||||
return &ListContext{
|
||||
return (&ListContext{
|
||||
BaseContext: context.NewBaseContext(context.NewBaseContextOpts{
|
||||
ViewName: "files",
|
||||
WindowName: "files",
|
||||
|
@ -360,11 +360,11 @@ func (gui *Gui) submodulesListContext() types.IListContext {
|
|||
}
|
||||
return item.ID()
|
||||
},
|
||||
}
|
||||
}).attachKeybindings()
|
||||
}
|
||||
|
||||
func (gui *Gui) suggestionsListContext() types.IListContext {
|
||||
return &ListContext{
|
||||
return (&ListContext{
|
||||
BaseContext: context.NewBaseContext(context.NewBaseContextOpts{
|
||||
ViewName: "suggestions",
|
||||
WindowName: "suggestions",
|
||||
|
@ -377,7 +377,7 @@ func (gui *Gui) suggestionsListContext() types.IListContext {
|
|||
GetDisplayStrings: func(startIdx int, length int) [][]string {
|
||||
return presentation.GetSuggestionListDisplayStrings(gui.State.Suggestions)
|
||||
},
|
||||
}
|
||||
}).attachKeybindings()
|
||||
}
|
||||
|
||||
func (gui *Gui) getListContexts() []types.IListContext {
|
||||
|
|
|
@ -28,6 +28,9 @@ type IBaseContext interface {
|
|||
GetKey() ContextKey
|
||||
|
||||
GetOptionsMap() map[string]string
|
||||
|
||||
GetKeybindings(opts KeybindingsOpts) []*Binding
|
||||
AddKeybindingsFn(KeybindingsFn)
|
||||
}
|
||||
|
||||
type Context interface {
|
||||
|
@ -46,12 +49,16 @@ type OnFocusOpts struct {
|
|||
|
||||
type ContextKey string
|
||||
|
||||
type KeybindingsOpts struct {
|
||||
GetKey func(key string) interface{}
|
||||
Config config.KeybindingConfig
|
||||
Guards KeybindingGuards
|
||||
}
|
||||
|
||||
type KeybindingsFn func(opts KeybindingsOpts) []*Binding
|
||||
|
||||
type HasKeybindings interface {
|
||||
Keybindings(
|
||||
getKey func(key string) interface{},
|
||||
config config.KeybindingConfig,
|
||||
guards KeybindingGuards,
|
||||
) []*Binding
|
||||
GetKeybindings(opts KeybindingsOpts) []*Binding
|
||||
}
|
||||
|
||||
type IController interface {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue