mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-04 23:37:41 +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
@ -395,6 +395,7 @@ type KeybindingUniversalConfig struct {
|
|||||||
NextBlockAlt2 string `yaml:"nextBlock-alt2"`
|
NextBlockAlt2 string `yaml:"nextBlock-alt2"`
|
||||||
PrevBlockAlt2 string `yaml:"prevBlock-alt2"`
|
PrevBlockAlt2 string `yaml:"prevBlock-alt2"`
|
||||||
JumpToBlock []string `yaml:"jumpToBlock"`
|
JumpToBlock []string `yaml:"jumpToBlock"`
|
||||||
|
FocusMainView string `yaml:"focusMainView"`
|
||||||
NextMatch string `yaml:"nextMatch"`
|
NextMatch string `yaml:"nextMatch"`
|
||||||
PrevMatch string `yaml:"prevMatch"`
|
PrevMatch string `yaml:"prevMatch"`
|
||||||
StartSearch string `yaml:"startSearch"`
|
StartSearch string `yaml:"startSearch"`
|
||||||
@ -876,6 +877,7 @@ func GetDefaultConfig() *UserConfig {
|
|||||||
PrevBlockAlt2: "<backtab>",
|
PrevBlockAlt2: "<backtab>",
|
||||||
NextBlockAlt2: "<tab>",
|
NextBlockAlt2: "<tab>",
|
||||||
JumpToBlock: []string{"1", "2", "3", "4", "5"},
|
JumpToBlock: []string{"1", "2", "3", "4", "5"},
|
||||||
|
FocusMainView: "0",
|
||||||
NextMatch: "n",
|
NextMatch: "n",
|
||||||
PrevMatch: "N",
|
PrevMatch: "N",
|
||||||
StartSearch: "/",
|
StartSearch: "/",
|
||||||
|
@ -17,11 +17,12 @@ func NewMainContext(
|
|||||||
ctx := &MainContext{
|
ctx := &MainContext{
|
||||||
SimpleContext: NewSimpleContext(
|
SimpleContext: NewSimpleContext(
|
||||||
NewBaseContext(NewBaseContextOpts{
|
NewBaseContext(NewBaseContextOpts{
|
||||||
Kind: types.MAIN_CONTEXT,
|
Kind: types.MAIN_CONTEXT,
|
||||||
View: view,
|
View: view,
|
||||||
WindowName: windowName,
|
WindowName: windowName,
|
||||||
Key: key,
|
Key: key,
|
||||||
Focusable: false,
|
Focusable: true,
|
||||||
|
HighlightOnFocus: false,
|
||||||
})),
|
})),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,6 +189,8 @@ func (gui *Gui) resetHelpersAndControllers() {
|
|||||||
patchExplorerControllerFactory := controllers.NewPatchExplorerControllerFactory(common)
|
patchExplorerControllerFactory := controllers.NewPatchExplorerControllerFactory(common)
|
||||||
stagingController := controllers.NewStagingController(common, gui.State.Contexts.Staging, gui.State.Contexts.StagingSecondary, false)
|
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)
|
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)
|
patchBuildingController := controllers.NewPatchBuildingController(common)
|
||||||
snakeController := controllers.NewSnakeController(common)
|
snakeController := controllers.NewSnakeController(common)
|
||||||
reflogCommitsController := controllers.NewReflogCommitsController(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{
|
for _, context := range []controllers.ContainsCommits{
|
||||||
gui.State.Contexts.LocalCommits,
|
gui.State.Contexts.LocalCommits,
|
||||||
gui.State.Contexts.ReflogCommits,
|
gui.State.Contexts.ReflogCommits,
|
||||||
@ -306,6 +324,16 @@ func (gui *Gui) resetHelpersAndControllers() {
|
|||||||
mergeConflictsController,
|
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,
|
controllers.AttachControllers(gui.State.Contexts.Files,
|
||||||
filesController,
|
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
|
IgnoreFile string
|
||||||
ExcludeFile string
|
ExcludeFile string
|
||||||
RefreshFiles string
|
RefreshFiles string
|
||||||
|
FocusMainView string
|
||||||
Merge string
|
Merge string
|
||||||
RegularMerge string
|
RegularMerge string
|
||||||
MergeBranchTooltip string
|
MergeBranchTooltip string
|
||||||
@ -508,6 +509,7 @@ type TranslationSet struct {
|
|||||||
EnterCommitFile string
|
EnterCommitFile string
|
||||||
EnterCommitFileTooltip string
|
EnterCommitFileTooltip string
|
||||||
ExitCustomPatchBuilder string
|
ExitCustomPatchBuilder string
|
||||||
|
ExitFocusedMainView string
|
||||||
EnterUpstream string
|
EnterUpstream string
|
||||||
InvalidUpstream string
|
InvalidUpstream string
|
||||||
ReturnToRemotesList string
|
ReturnToRemotesList string
|
||||||
@ -1328,6 +1330,7 @@ func EnglishTranslationSet() *TranslationSet {
|
|||||||
IgnoreFile: `Add to .gitignore`,
|
IgnoreFile: `Add to .gitignore`,
|
||||||
ExcludeFile: `Add to .git/info/exclude`,
|
ExcludeFile: `Add to .git/info/exclude`,
|
||||||
RefreshFiles: `Refresh files`,
|
RefreshFiles: `Refresh files`,
|
||||||
|
FocusMainView: "Focus main view",
|
||||||
Merge: `Merge`,
|
Merge: `Merge`,
|
||||||
RegularMerge: "Regular merge",
|
RegularMerge: "Regular merge",
|
||||||
MergeBranchTooltip: "View options for merging the selected item into the current branch (regular merge, squash 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",
|
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.",
|
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`,
|
ExitCustomPatchBuilder: `Exit custom patch builder`,
|
||||||
|
ExitFocusedMainView: "Exit back to side panel",
|
||||||
EnterUpstream: `Enter upstream as '<remote> <branchname>'`,
|
EnterUpstream: `Enter upstream as '<remote> <branchname>'`,
|
||||||
InvalidUpstream: "Invalid upstream. Must be in the format '<remote> <branchname>'",
|
InvalidUpstream: "Invalid upstream. Must be in the format '<remote> <branchname>'",
|
||||||
ReturnToRemotesList: `Return to remotes list`,
|
ReturnToRemotesList: `Return to remotes list`,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user