mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 20:36:03 +02:00
Allow focussing the main view
In this commit this is only possible by pressing '0' in a side panel; we'll add mouse clicking later in the branch. Also, you can't really do anything in the focused view except press escape to leave it again. We'll add some more functionality in a following commit.
This commit is contained in:
parent
b7b7c65999
commit
1a93b2324b
6 changed files with 152 additions and 5 deletions
|
@ -395,6 +395,7 @@ type KeybindingUniversalConfig struct {
|
|||
NextBlockAlt2 string `yaml:"nextBlock-alt2"`
|
||||
PrevBlockAlt2 string `yaml:"prevBlock-alt2"`
|
||||
JumpToBlock []string `yaml:"jumpToBlock"`
|
||||
FocusMainView string `yaml:"focusMainView"`
|
||||
NextMatch string `yaml:"nextMatch"`
|
||||
PrevMatch string `yaml:"prevMatch"`
|
||||
StartSearch string `yaml:"startSearch"`
|
||||
|
@ -876,6 +877,7 @@ func GetDefaultConfig() *UserConfig {
|
|||
PrevBlockAlt2: "<backtab>",
|
||||
NextBlockAlt2: "<tab>",
|
||||
JumpToBlock: []string{"1", "2", "3", "4", "5"},
|
||||
FocusMainView: "0",
|
||||
NextMatch: "n",
|
||||
PrevMatch: "N",
|
||||
StartSearch: "/",
|
||||
|
|
|
@ -17,11 +17,12 @@ func NewMainContext(
|
|||
ctx := &MainContext{
|
||||
SimpleContext: NewSimpleContext(
|
||||
NewBaseContext(NewBaseContextOpts{
|
||||
Kind: types.MAIN_CONTEXT,
|
||||
View: view,
|
||||
WindowName: windowName,
|
||||
Key: key,
|
||||
Focusable: false,
|
||||
Kind: types.MAIN_CONTEXT,
|
||||
View: view,
|
||||
WindowName: windowName,
|
||||
Key: key,
|
||||
Focusable: true,
|
||||
HighlightOnFocus: false,
|
||||
})),
|
||||
}
|
||||
|
||||
|
|
|
@ -189,6 +189,8 @@ func (gui *Gui) resetHelpersAndControllers() {
|
|||
patchExplorerControllerFactory := controllers.NewPatchExplorerControllerFactory(common)
|
||||
stagingController := controllers.NewStagingController(common, gui.State.Contexts.Staging, gui.State.Contexts.StagingSecondary, false)
|
||||
stagingSecondaryController := controllers.NewStagingController(common, gui.State.Contexts.StagingSecondary, gui.State.Contexts.Staging, true)
|
||||
mainViewController := controllers.NewMainViewController(common, gui.State.Contexts.Normal, gui.State.Contexts.NormalSecondary)
|
||||
secondaryViewController := controllers.NewMainViewController(common, gui.State.Contexts.NormalSecondary, gui.State.Contexts.Normal)
|
||||
patchBuildingController := controllers.NewPatchBuildingController(common)
|
||||
snakeController := controllers.NewSnakeController(common)
|
||||
reflogCommitsController := controllers.NewReflogCommitsController(common)
|
||||
|
@ -263,6 +265,22 @@ func (gui *Gui) resetHelpersAndControllers() {
|
|||
))
|
||||
}
|
||||
|
||||
for _, context := range []types.Context{
|
||||
gui.State.Contexts.Files,
|
||||
gui.State.Contexts.Branches,
|
||||
gui.State.Contexts.RemoteBranches,
|
||||
gui.State.Contexts.Tags,
|
||||
gui.State.Contexts.LocalCommits,
|
||||
gui.State.Contexts.ReflogCommits,
|
||||
gui.State.Contexts.SubCommits,
|
||||
gui.State.Contexts.CommitFiles,
|
||||
gui.State.Contexts.Stash,
|
||||
} {
|
||||
controllers.AttachControllers(context, controllers.NewSwitchToFocusedMainViewController(
|
||||
common, context,
|
||||
))
|
||||
}
|
||||
|
||||
for _, context := range []controllers.ContainsCommits{
|
||||
gui.State.Contexts.LocalCommits,
|
||||
gui.State.Contexts.ReflogCommits,
|
||||
|
@ -306,6 +324,16 @@ func (gui *Gui) resetHelpersAndControllers() {
|
|||
mergeConflictsController,
|
||||
)
|
||||
|
||||
controllers.AttachControllers(gui.State.Contexts.Normal,
|
||||
mainViewController,
|
||||
verticalScrollControllerFactory.Create(gui.State.Contexts.Normal),
|
||||
)
|
||||
|
||||
controllers.AttachControllers(gui.State.Contexts.NormalSecondary,
|
||||
secondaryViewController,
|
||||
verticalScrollControllerFactory.Create(gui.State.Contexts.NormalSecondary),
|
||||
)
|
||||
|
||||
controllers.AttachControllers(gui.State.Contexts.Files,
|
||||
filesController,
|
||||
)
|
||||
|
|
63
pkg/gui/controllers/main_view_controller.go
Normal file
63
pkg/gui/controllers/main_view_controller.go
Normal file
|
@ -0,0 +1,63 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
)
|
||||
|
||||
type MainViewController struct {
|
||||
baseController
|
||||
c *ControllerCommon
|
||||
|
||||
context types.Context
|
||||
otherContext types.Context
|
||||
}
|
||||
|
||||
var _ types.IController = &MainViewController{}
|
||||
|
||||
func NewMainViewController(
|
||||
c *ControllerCommon,
|
||||
context types.Context,
|
||||
otherContext types.Context,
|
||||
) *MainViewController {
|
||||
return &MainViewController{
|
||||
baseController: baseController{},
|
||||
c: c,
|
||||
context: context,
|
||||
otherContext: otherContext,
|
||||
}
|
||||
}
|
||||
|
||||
func (self *MainViewController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
|
||||
return []*types.Binding{
|
||||
{
|
||||
Key: opts.GetKey(opts.Config.Universal.TogglePanel),
|
||||
Handler: self.togglePanel,
|
||||
Description: self.c.Tr.ToggleStagingView,
|
||||
Tooltip: self.c.Tr.ToggleStagingViewTooltip,
|
||||
DisplayOnScreen: true,
|
||||
},
|
||||
{
|
||||
Key: opts.GetKey(opts.Config.Universal.Return),
|
||||
Handler: self.escape,
|
||||
Description: self.c.Tr.ExitFocusedMainView,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (self *MainViewController) Context() types.Context {
|
||||
return self.context
|
||||
}
|
||||
|
||||
func (self *MainViewController) togglePanel() error {
|
||||
if self.otherContext.GetView().Visible {
|
||||
self.otherContext.SetParentContext(self.context.GetParentContext())
|
||||
self.c.Context().Push(self.otherContext, types.OnFocusOpts{})
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *MainViewController) escape() error {
|
||||
self.c.Context().Pop()
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
)
|
||||
|
||||
// This controller is for all contexts that can focus their main view.
|
||||
|
||||
var _ types.IController = &SwitchToFocusedMainViewController{}
|
||||
|
||||
type SwitchToFocusedMainViewController struct {
|
||||
baseController
|
||||
c *ControllerCommon
|
||||
context types.Context
|
||||
}
|
||||
|
||||
func NewSwitchToFocusedMainViewController(
|
||||
c *ControllerCommon,
|
||||
context types.Context,
|
||||
) *SwitchToFocusedMainViewController {
|
||||
return &SwitchToFocusedMainViewController{
|
||||
baseController: baseController{},
|
||||
c: c,
|
||||
context: context,
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SwitchToFocusedMainViewController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
|
||||
bindings := []*types.Binding{
|
||||
{
|
||||
Key: opts.GetKey(opts.Config.Universal.FocusMainView),
|
||||
Handler: self.handleFocusMainView,
|
||||
Description: self.c.Tr.FocusMainView,
|
||||
},
|
||||
}
|
||||
|
||||
return bindings
|
||||
}
|
||||
|
||||
func (self *SwitchToFocusedMainViewController) Context() types.Context {
|
||||
return self.context
|
||||
}
|
||||
|
||||
func (self *SwitchToFocusedMainViewController) handleFocusMainView() error {
|
||||
mainViewContext := self.c.Helpers().Window.GetContextForWindow("main")
|
||||
mainViewContext.SetParentContext(self.context)
|
||||
self.c.Context().Push(mainViewContext, types.OnFocusOpts{})
|
||||
return nil
|
||||
}
|
|
@ -264,6 +264,7 @@ type TranslationSet struct {
|
|||
IgnoreFile string
|
||||
ExcludeFile string
|
||||
RefreshFiles string
|
||||
FocusMainView string
|
||||
Merge string
|
||||
RegularMerge string
|
||||
MergeBranchTooltip string
|
||||
|
@ -508,6 +509,7 @@ type TranslationSet struct {
|
|||
EnterCommitFile string
|
||||
EnterCommitFileTooltip string
|
||||
ExitCustomPatchBuilder string
|
||||
ExitFocusedMainView string
|
||||
EnterUpstream string
|
||||
InvalidUpstream string
|
||||
ReturnToRemotesList string
|
||||
|
@ -1328,6 +1330,7 @@ func EnglishTranslationSet() *TranslationSet {
|
|||
IgnoreFile: `Add to .gitignore`,
|
||||
ExcludeFile: `Add to .git/info/exclude`,
|
||||
RefreshFiles: `Refresh files`,
|
||||
FocusMainView: "Focus main view",
|
||||
Merge: `Merge`,
|
||||
RegularMerge: "Regular merge",
|
||||
MergeBranchTooltip: "View options for merging the selected item into the current branch (regular merge, squash merge)",
|
||||
|
@ -1581,6 +1584,7 @@ func EnglishTranslationSet() *TranslationSet {
|
|||
EnterCommitFile: "Enter file / Toggle directory collapsed",
|
||||
EnterCommitFileTooltip: "If a file is selected, enter the file so that you can add/remove individual lines to the custom patch. If a directory is selected, toggle the directory.",
|
||||
ExitCustomPatchBuilder: `Exit custom patch builder`,
|
||||
ExitFocusedMainView: "Exit back to side panel",
|
||||
EnterUpstream: `Enter upstream as '<remote> <branchname>'`,
|
||||
InvalidUpstream: "Invalid upstream. Must be in the format '<remote> <branchname>'",
|
||||
ReturnToRemotesList: `Return to remotes list`,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue