Skip to content

Commit 468f919

Browse files
committed
Select line that is in the middle of the screen
1 parent a15d3fb commit 468f919

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pkg/gui/controllers/main_view_controller.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ func (self *MainViewController) Context() types.Context {
4848
return self.context
4949
}
5050

51+
func (self *MainViewController) GetOnFocus() func(types.OnFocusOpts) {
52+
return func(opts types.OnFocusOpts) {
53+
if opts.ClickedWindowName != "" {
54+
self.context.GetView().FocusPoint(0, opts.ClickedViewLineIdx)
55+
}
56+
}
57+
}
58+
5159
func (self *MainViewController) togglePanel() error {
5260
if self.otherContext.GetView().Visible {
5361
self.c.Context().Push(self.otherContext)

pkg/gui/controllers/switch_to_focused_main_view_controller.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package controllers
22

33
import (
44
"github.com/jesseduffield/lazygit/pkg/gui/types"
5+
"github.com/samber/lo"
56
)
67

78
// This controller is for all contexts that can focus their main view.
@@ -44,6 +45,10 @@ func (self *SwitchToFocusedMainViewController) Context() types.Context {
4445
func (self *SwitchToFocusedMainViewController) handleFocusMainView() error {
4546
mainViewContext := self.c.Helpers().Window.GetContextForWindow("main")
4647
mainViewContext.SetParentContext(self.context)
47-
self.c.Context().Push(mainViewContext, types.OnFocusOpts{})
48+
mainView := mainViewContext.GetView()
49+
lineIdx := mainView.OriginY() + mainView.Height()/2
50+
lineIdx = lo.Clamp(lineIdx, 0, mainView.LinesHeight()-1)
51+
self.c.Context().Push(mainViewContext,
52+
types.OnFocusOpts{ClickedWindowName: "main", ClickedViewLineIdx: lineIdx})
4853
return nil
4954
}

0 commit comments

Comments
 (0)