Skip to content

Commit 1bb3147

Browse files
committed
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.
1 parent cbd97d3 commit 1bb3147

File tree

6 files changed

+152
-5
lines changed

6 files changed

+152
-5
lines changed

pkg/config/user_config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ type KeybindingUniversalConfig struct {
395395
NextBlockAlt2 string `yaml:"nextBlock-alt2"`
396396
PrevBlockAlt2 string `yaml:"prevBlock-alt2"`
397397
JumpToBlock []string `yaml:"jumpToBlock"`
398+
FocusMainView string `yaml:"focusMainView"`
398399
NextMatch string `yaml:"nextMatch"`
399400
PrevMatch string `yaml:"prevMatch"`
400401
StartSearch string `yaml:"startSearch"`
@@ -871,6 +872,7 @@ func GetDefaultConfig() *UserConfig {
871872
PrevBlockAlt2: "<backtab>",
872873
NextBlockAlt2: "<tab>",
873874
JumpToBlock: []string{"1", "2", "3", "4", "5"},
875+
FocusMainView: "0",
874876
NextMatch: "n",
875877
PrevMatch: "N",
876878
StartSearch: "/",

pkg/gui/context/main_context.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ func NewMainContext(
1717
ctx := &MainContext{
1818
SimpleContext: NewSimpleContext(
1919
NewBaseContext(NewBaseContextOpts{
20-
Kind: types.MAIN_CONTEXT,
21-
View: view,
22-
WindowName: windowName,
23-
Key: key,
24-
Focusable: false,
20+
Kind: types.MAIN_CONTEXT,
21+
View: view,
22+
WindowName: windowName,
23+
Key: key,
24+
Focusable: true,
25+
HighlightOnFocus: false,
2526
})),
2627
}
2728

pkg/gui/controllers.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ func (gui *Gui) resetHelpersAndControllers() {
189189
patchExplorerControllerFactory := controllers.NewPatchExplorerControllerFactory(common)
190190
stagingController := controllers.NewStagingController(common, gui.State.Contexts.Staging, gui.State.Contexts.StagingSecondary, false)
191191
stagingSecondaryController := controllers.NewStagingController(common, gui.State.Contexts.StagingSecondary, gui.State.Contexts.Staging, true)
192+
mainViewController := controllers.NewMainViewController(common, gui.State.Contexts.Normal, gui.State.Contexts.NormalSecondary)
193+
secondaryViewController := controllers.NewMainViewController(common, gui.State.Contexts.NormalSecondary, gui.State.Contexts.Normal)
192194
patchBuildingController := controllers.NewPatchBuildingController(common)
193195
snakeController := controllers.NewSnakeController(common)
194196
reflogCommitsController := controllers.NewReflogCommitsController(common)
@@ -263,6 +265,22 @@ func (gui *Gui) resetHelpersAndControllers() {
263265
))
264266
}
265267

268+
for _, context := range []types.Context{
269+
gui.State.Contexts.Files,
270+
gui.State.Contexts.Branches,
271+
gui.State.Contexts.RemoteBranches,
272+
gui.State.Contexts.Tags,
273+
gui.State.Contexts.LocalCommits,
274+
gui.State.Contexts.ReflogCommits,
275+
gui.State.Contexts.SubCommits,
276+
gui.State.Contexts.CommitFiles,
277+
gui.State.Contexts.Stash,
278+
} {
279+
controllers.AttachControllers(context, controllers.NewSwitchToFocusedMainViewController(
280+
common, context,
281+
))
282+
}
283+
266284
for _, context := range []controllers.ContainsCommits{
267285
gui.State.Contexts.LocalCommits,
268286
gui.State.Contexts.ReflogCommits,
@@ -306,6 +324,16 @@ func (gui *Gui) resetHelpersAndControllers() {
306324
mergeConflictsController,
307325
)
308326

327+
controllers.AttachControllers(gui.State.Contexts.Normal,
328+
mainViewController,
329+
verticalScrollControllerFactory.Create(gui.State.Contexts.Normal),
330+
)
331+
332+
controllers.AttachControllers(gui.State.Contexts.NormalSecondary,
333+
secondaryViewController,
334+
verticalScrollControllerFactory.Create(gui.State.Contexts.NormalSecondary),
335+
)
336+
309337
controllers.AttachControllers(gui.State.Contexts.Files,
310338
filesController,
311339
)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package controllers
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/gui/types"
5+
)
6+
7+
type MainViewController struct {
8+
baseController
9+
c *ControllerCommon
10+
11+
context types.Context
12+
otherContext types.Context
13+
}
14+
15+
var _ types.IController = &MainViewController{}
16+
17+
func NewMainViewController(
18+
c *ControllerCommon,
19+
context types.Context,
20+
otherContext types.Context,
21+
) *MainViewController {
22+
return &MainViewController{
23+
baseController: baseController{},
24+
c: c,
25+
context: context,
26+
otherContext: otherContext,
27+
}
28+
}
29+
30+
func (self *MainViewController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
31+
return []*types.Binding{
32+
{
33+
Key: opts.GetKey(opts.Config.Universal.TogglePanel),
34+
Handler: self.togglePanel,
35+
Description: self.c.Tr.ToggleStagingView,
36+
Tooltip: self.c.Tr.ToggleStagingViewTooltip,
37+
DisplayOnScreen: true,
38+
},
39+
{
40+
Key: opts.GetKey(opts.Config.Universal.Return),
41+
Handler: self.escape,
42+
Description: self.c.Tr.ExitFocusedMainView,
43+
},
44+
}
45+
}
46+
47+
func (self *MainViewController) Context() types.Context {
48+
return self.context
49+
}
50+
51+
func (self *MainViewController) togglePanel() error {
52+
if self.otherContext.GetView().Visible {
53+
self.otherContext.SetParentContext(self.context.GetParentContext())
54+
self.c.Context().Push(self.otherContext)
55+
}
56+
57+
return nil
58+
}
59+
60+
func (self *MainViewController) escape() error {
61+
self.c.Context().Pop()
62+
return nil
63+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package controllers
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/gui/types"
5+
)
6+
7+
// This controller is for all contexts that can focus their main view.
8+
9+
var _ types.IController = &SwitchToFocusedMainViewController{}
10+
11+
type SwitchToFocusedMainViewController struct {
12+
baseController
13+
c *ControllerCommon
14+
context types.Context
15+
}
16+
17+
func NewSwitchToFocusedMainViewController(
18+
c *ControllerCommon,
19+
context types.Context,
20+
) *SwitchToFocusedMainViewController {
21+
return &SwitchToFocusedMainViewController{
22+
baseController: baseController{},
23+
c: c,
24+
context: context,
25+
}
26+
}
27+
28+
func (self *SwitchToFocusedMainViewController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
29+
bindings := []*types.Binding{
30+
{
31+
Key: opts.GetKey(opts.Config.Universal.FocusMainView),
32+
Handler: self.handleFocusMainView,
33+
Description: self.c.Tr.FocusMainView,
34+
},
35+
}
36+
37+
return bindings
38+
}
39+
40+
func (self *SwitchToFocusedMainViewController) Context() types.Context {
41+
return self.context
42+
}
43+
44+
func (self *SwitchToFocusedMainViewController) handleFocusMainView() error {
45+
mainViewContext := self.c.Helpers().Window.GetContextForWindow("main")
46+
mainViewContext.SetParentContext(self.context)
47+
self.c.Context().Push(mainViewContext, types.OnFocusOpts{})
48+
return nil
49+
}

pkg/i18n/english.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ type TranslationSet struct {
254254
IgnoreFile string
255255
ExcludeFile string
256256
RefreshFiles string
257+
FocusMainView string
257258
Merge string
258259
RegularMerge string
259260
MergeBranchTooltip string
@@ -486,6 +487,7 @@ type TranslationSet struct {
486487
EnterCommitFile string
487488
EnterCommitFileTooltip string
488489
ExitCustomPatchBuilder string
490+
ExitFocusedMainView string
489491
EnterUpstream string
490492
InvalidUpstream string
491493
ReturnToRemotesList string
@@ -1293,6 +1295,7 @@ func EnglishTranslationSet() *TranslationSet {
12931295
IgnoreFile: `Add to .gitignore`,
12941296
ExcludeFile: `Add to .git/info/exclude`,
12951297
RefreshFiles: `Refresh files`,
1298+
FocusMainView: "Focus main view",
12961299
Merge: `Merge`,
12971300
RegularMerge: "Regular merge",
12981301
MergeBranchTooltip: "View options for merging the selected item into the current branch (regular merge, squash merge)",
@@ -1534,6 +1537,7 @@ func EnglishTranslationSet() *TranslationSet {
15341537
EnterCommitFile: "Enter file / Toggle directory collapsed",
15351538
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.",
15361539
ExitCustomPatchBuilder: `Exit custom patch builder`,
1540+
ExitFocusedMainView: "Exit back to side panel",
15371541
EnterUpstream: `Enter upstream as '<remote> <branchname>'`,
15381542
InvalidUpstream: "Invalid upstream. Must be in the format '<remote> <branchname>'",
15391543
ReturnToRemotesList: `Return to remotes list`,

0 commit comments

Comments
 (0)