Skip to content

Commit 37be9db

Browse files
committed
support scrolling left and right
1 parent f6ec7ba commit 37be9db

File tree

16 files changed

+140
-17
lines changed

16 files changed

+140
-17
lines changed

docs/Config.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ keybinding:
107107
nextPage: '.' # go to previous page in list
108108
gotoTop: '<' # go to top of list
109109
gotoBottom: '>' # go to bottom of list
110+
scrollLeft: 'H' # scroll left within list view
111+
scrollRight: 'L' # scroll right within list view
110112
prevBlock: '<left>' # goto the previous block / panel
111113
nextBlock: '<right>' # goto the next block / panel
112114
prevBlock-alt: 'h' # goto the previous block / panel

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ require (
2020
github.com/imdario/mergo v0.3.11
2121
github.com/integrii/flaggy v1.4.0
2222
github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4
23-
github.com/jesseduffield/gocui v0.3.1-0.20211102081536-e4eee64f4d13
23+
github.com/jesseduffield/gocui v0.3.1-0.20211102093457-be3a05cf7131
2424
github.com/jesseduffield/minimal/gitignore v0.3.3-0.20211018110810-9cde264e6b1e
2525
github.com/jesseduffield/yaml v2.1.0+incompatible
2626
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOl
7171
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
7272
github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4 h1:GOQrmaE8i+KEdB8NzAegKYd4tPn/inM0I1uo0NXFerg=
7373
github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4/go.mod h1:nGNEErzf+NRznT+N2SWqmHnDnF9aLgANB1CUNEan09o=
74-
github.com/jesseduffield/gocui v0.3.1-0.20211102081536-e4eee64f4d13 h1:JB1nYX2l3s9aBtw4Ymc7KXp/Hk3IukO4u+APok6WWjo=
75-
github.com/jesseduffield/gocui v0.3.1-0.20211102081536-e4eee64f4d13/go.mod h1:znJuCDnF2Ph40YZSlBwdX/4GEofnIoWLGdT4mK5zRAU=
74+
github.com/jesseduffield/gocui v0.3.1-0.20211102093457-be3a05cf7131 h1:gojgTjfrDjDtpjcFeY/IVPGufQPOi/gTgg3wQ9FESmc=
75+
github.com/jesseduffield/gocui v0.3.1-0.20211102093457-be3a05cf7131/go.mod h1:znJuCDnF2Ph40YZSlBwdX/4GEofnIoWLGdT4mK5zRAU=
7676
github.com/jesseduffield/minimal/gitignore v0.3.3-0.20211018110810-9cde264e6b1e h1:uw/oo+kg7t/oeMs6sqlAwr85ND/9cpO3up3VxphxY0U=
7777
github.com/jesseduffield/minimal/gitignore v0.3.3-0.20211018110810-9cde264e6b1e/go.mod h1:u60qdFGXRd36jyEXxetz0vQceQIxzI13lIo3EFUDf4I=
7878
github.com/jesseduffield/yaml v2.1.0+incompatible h1:HWQJ1gIv2zHKbDYNp0Jwjlj24K8aqpFHnMCynY1EpmE=

pkg/config/user_config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ type KeybindingUniversalConfig struct {
125125
NextItemAlt string `yaml:"nextItem-alt"`
126126
PrevPage string `yaml:"prevPage"`
127127
NextPage string `yaml:"nextPage"`
128+
ScrollLeft string `yaml:"scrollLeft"`
129+
ScrollRight string `yaml:"scrollRight"`
128130
GotoTop string `yaml:"gotoTop"`
129131
GotoBottom string `yaml:"gotoBottom"`
130132
PrevBlock string `yaml:"prevBlock"`
@@ -382,6 +384,8 @@ func GetDefaultConfig() *UserConfig {
382384
NextItemAlt: "j",
383385
PrevPage: ",",
384386
NextPage: ".",
387+
ScrollLeft: "H",
388+
ScrollRight: "L",
385389
GotoTop: "<",
386390
GotoBottom: ">",
387391
PrevBlock: "<left>",

pkg/gui/context.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,8 @@ func (gui *Gui) onViewFocusLost(oldView *gocui.View, newView *gocui.View) error
399399
return nil
400400
}
401401

402+
_ = oldView.SetOriginX(0)
403+
402404
if oldView == gui.Views.CommitFiles && newView != gui.Views.Main && newView != gui.Views.Secondary && newView != gui.Views.Search {
403405
gui.resetWindowForView(gui.Views.CommitFiles)
404406
if err := gui.deactivateContext(gui.State.Contexts.CommitFiles); err != nil {

pkg/gui/global_handlers.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"github.com/jesseduffield/lazygit/pkg/utils"
1111
)
1212

13+
const HORIZONTAL_SCROLL_FACTOR = 3
14+
1315
// these views need to be re-rendered when the screen mode changes. The commits view,
1416
// for example, will show authorship information in half and full screen mode.
1517
func (gui *Gui) rerenderViewsWithScreenModeDependentContent() error {
@@ -114,20 +116,41 @@ func (gui *Gui) linesToScrollDown(view *gocui.View) int {
114116

115117
func (gui *Gui) scrollUpMain() error {
116118
if gui.canScrollMergePanel() {
117-
gui.State.Panels.Merging.UserScrolling = true
119+
gui.State.Panels.Merging.UserVerticalScrolling = true
118120
}
119121

120122
return gui.scrollUpView(gui.Views.Main)
121123
}
122124

123125
func (gui *Gui) scrollDownMain() error {
124126
if gui.canScrollMergePanel() {
125-
gui.State.Panels.Merging.UserScrolling = true
127+
gui.State.Panels.Merging.UserVerticalScrolling = true
126128
}
127129

128130
return gui.scrollDownView(gui.Views.Main)
129131
}
130132

133+
func (gui *Gui) scrollLeftMain() error {
134+
gui.scrollLeft(gui.Views.Main)
135+
136+
return nil
137+
}
138+
139+
func (gui *Gui) scrollRightMain() error {
140+
gui.scrollRight(gui.Views.Main)
141+
142+
return nil
143+
}
144+
145+
func (gui *Gui) scrollLeft(view *gocui.View) {
146+
newOriginX := utils.Max(view.OriginX()-view.InnerWidth()/HORIZONTAL_SCROLL_FACTOR, 0)
147+
_ = view.SetOriginX(newOriginX)
148+
}
149+
150+
func (gui *Gui) scrollRight(view *gocui.View) {
151+
_ = view.SetOriginX(view.OriginX() + view.InnerWidth()/HORIZONTAL_SCROLL_FACTOR)
152+
}
153+
131154
func (gui *Gui) scrollUpSecondary() error {
132155
return gui.scrollUpView(gui.Views.Secondary)
133156
}

pkg/gui/gui.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ type LblPanelState struct {
145145
type MergingPanelState struct {
146146
*mergeconflicts.State
147147

148-
// UserScrolling tells us if the user has started scrolling through the file themselves
148+
// UserVerticalScrolling tells us if the user has started scrolling through the file themselves
149149
// in which case we won't auto-scroll to a conflict.
150-
UserScrolling bool
150+
UserVerticalScrolling bool
151151
}
152152

153153
type filePanelState struct {
@@ -403,8 +403,8 @@ func (gui *Gui) resetState(filterPath string, reuseState bool) {
403403
Menu: &menuPanelState{listPanelState: listPanelState{SelectedLineIdx: 0}, OnPress: nil},
404404
Suggestions: &suggestionsPanelState{listPanelState: listPanelState{SelectedLineIdx: 0}},
405405
Merging: &MergingPanelState{
406-
State: mergeconflicts.NewState(),
407-
UserScrolling: false,
406+
State: mergeconflicts.NewState(),
407+
UserVerticalScrolling: false,
408408
},
409409
},
410410
Ptmx: nil,

pkg/gui/keybindings.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,6 +1426,20 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
14261426
Modifier: gocui.ModNone,
14271427
Handler: gui.scrollDownMain,
14281428
},
1429+
{
1430+
ViewName: "main",
1431+
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY), string(MAIN_MERGING_CONTEXT_KEY)},
1432+
Key: gui.getKey(config.Universal.ScrollLeft),
1433+
Handler: gui.scrollLeftMain,
1434+
Description: gui.Tr.LcScrollLeft,
1435+
},
1436+
{
1437+
ViewName: "main",
1438+
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY), string(MAIN_MERGING_CONTEXT_KEY)},
1439+
Key: gui.getKey(config.Universal.ScrollRight),
1440+
Handler: gui.scrollRightMain,
1441+
Description: gui.Tr.LcScrollRight,
1442+
},
14291443
{
14301444
ViewName: "main",
14311445
Contexts: []string{string(MAIN_STAGING_CONTEXT_KEY)},

pkg/gui/line_by_line_panel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func (gui *Gui) focusSelection(state *LblPanelState) error {
174174
newOrigin := state.CalculateOrigin(origin, bufferHeight)
175175

176176
gui.g.Update(func(*gocui.Gui) error {
177-
if err := stagingView.SetOrigin(0, newOrigin); err != nil {
177+
if err := stagingView.SetOriginY(newOrigin); err != nil {
178178
return err
179179
}
180180

pkg/gui/list_context.go

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ type IListContext interface {
3030
OnRender() error
3131
handlePrevLine() error
3232
handleNextLine() error
33+
handleScrollLeft() error
34+
handleScrollRight() error
3335
handleLineChange(change int) error
3436
handleNextPage() error
3537
handleGotoTop() error
@@ -69,7 +71,7 @@ func (self *ListContext) FocusLine() {
6971
}
7072

7173
// we need a way of knowing whether we've rendered to the view yet.
72-
view.FocusPoint(0, self.GetPanelState().GetSelectedLineIdx())
74+
view.FocusPoint(view.OriginX(), self.GetPanelState().GetSelectedLineIdx())
7375
if self.RenderSelection {
7476
_, originY := view.Origin()
7577
displayStrings := self.GetDisplayStrings(originY, view.InnerHeight())
@@ -117,6 +119,13 @@ func (self *ListContext) HandleFocusLost() error {
117119
return self.OnFocusLost()
118120
}
119121

122+
view, err := self.Gui.g.View(self.ViewName)
123+
if err != nil {
124+
return nil
125+
}
126+
127+
_ = view.SetOriginX(0)
128+
120129
return nil
121130
}
122131

@@ -150,8 +159,44 @@ func (self *ListContext) handleNextLine() error {
150159
return self.handleLineChange(1)
151160
}
152161

162+
func (self *ListContext) handleScrollLeft() error {
163+
if self.ignoreKeybinding() {
164+
return nil
165+
}
166+
167+
// get the view, move the origin
168+
view, err := self.Gui.g.View(self.ViewName)
169+
if err != nil {
170+
return nil
171+
}
172+
173+
self.Gui.scrollLeft(view)
174+
175+
return self.HandleFocus()
176+
}
177+
178+
func (self *ListContext) handleScrollRight() error {
179+
if self.ignoreKeybinding() {
180+
return nil
181+
}
182+
183+
// get the view, move the origin
184+
view, err := self.Gui.g.View(self.ViewName)
185+
if err != nil {
186+
return nil
187+
}
188+
189+
self.Gui.scrollRight(view)
190+
191+
return self.HandleFocus()
192+
}
193+
194+
func (self *ListContext) ignoreKeybinding() bool {
195+
return !self.Gui.isPopupPanel(self.ViewName) && self.Gui.popupPanelFocused()
196+
}
197+
153198
func (self *ListContext) handleLineChange(change int) error {
154-
if !self.Gui.isPopupPanel(self.ViewName) && self.Gui.popupPanelFocused() {
199+
if self.ignoreKeybinding() {
155200
return nil
156201
}
157202

@@ -195,7 +240,7 @@ func (self *ListContext) handlePrevPage() error {
195240
}
196241

197242
func (self *ListContext) handleClick() error {
198-
if !self.Gui.isPopupPanel(self.ViewName) && self.Gui.popupPanelFocused() {
243+
if self.ignoreKeybinding() {
199244
return nil
200245
}
201246

0 commit comments

Comments
 (0)