1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-19 00:28:03 +02:00

support scrolling left and right

This commit is contained in:
Jesse Duffield
2021-11-02 20:35:53 +11:00
parent f6ec7babf5
commit 37be9dbea1
16 changed files with 140 additions and 17 deletions

View File

@ -107,6 +107,8 @@ keybinding:
nextPage: '.' # go to previous page in list nextPage: '.' # go to previous page in list
gotoTop: '<' # go to top of list gotoTop: '<' # go to top of list
gotoBottom: '>' # go to bottom of list gotoBottom: '>' # go to bottom of list
scrollLeft: 'H' # scroll left within list view
scrollRight: 'L' # scroll right within list view
prevBlock: '<left>' # goto the previous block / panel prevBlock: '<left>' # goto the previous block / panel
nextBlock: '<right>' # goto the next block / panel nextBlock: '<right>' # goto the next block / panel
prevBlock-alt: 'h' # goto the previous block / panel prevBlock-alt: 'h' # goto the previous block / panel

2
go.mod
View File

@ -20,7 +20,7 @@ require (
github.com/imdario/mergo v0.3.11 github.com/imdario/mergo v0.3.11
github.com/integrii/flaggy v1.4.0 github.com/integrii/flaggy v1.4.0
github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4 github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4
github.com/jesseduffield/gocui v0.3.1-0.20211102081536-e4eee64f4d13 github.com/jesseduffield/gocui v0.3.1-0.20211102093457-be3a05cf7131
github.com/jesseduffield/minimal/gitignore v0.3.3-0.20211018110810-9cde264e6b1e github.com/jesseduffield/minimal/gitignore v0.3.3-0.20211018110810-9cde264e6b1e
github.com/jesseduffield/yaml v2.1.0+incompatible github.com/jesseduffield/yaml v2.1.0+incompatible
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0

4
go.sum
View File

@ -71,8 +71,8 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOl
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4 h1:GOQrmaE8i+KEdB8NzAegKYd4tPn/inM0I1uo0NXFerg= github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4 h1:GOQrmaE8i+KEdB8NzAegKYd4tPn/inM0I1uo0NXFerg=
github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4/go.mod h1:nGNEErzf+NRznT+N2SWqmHnDnF9aLgANB1CUNEan09o= github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4/go.mod h1:nGNEErzf+NRznT+N2SWqmHnDnF9aLgANB1CUNEan09o=
github.com/jesseduffield/gocui v0.3.1-0.20211102081536-e4eee64f4d13 h1:JB1nYX2l3s9aBtw4Ymc7KXp/Hk3IukO4u+APok6WWjo= github.com/jesseduffield/gocui v0.3.1-0.20211102093457-be3a05cf7131 h1:gojgTjfrDjDtpjcFeY/IVPGufQPOi/gTgg3wQ9FESmc=
github.com/jesseduffield/gocui v0.3.1-0.20211102081536-e4eee64f4d13/go.mod h1:znJuCDnF2Ph40YZSlBwdX/4GEofnIoWLGdT4mK5zRAU= github.com/jesseduffield/gocui v0.3.1-0.20211102093457-be3a05cf7131/go.mod h1:znJuCDnF2Ph40YZSlBwdX/4GEofnIoWLGdT4mK5zRAU=
github.com/jesseduffield/minimal/gitignore v0.3.3-0.20211018110810-9cde264e6b1e h1:uw/oo+kg7t/oeMs6sqlAwr85ND/9cpO3up3VxphxY0U= github.com/jesseduffield/minimal/gitignore v0.3.3-0.20211018110810-9cde264e6b1e h1:uw/oo+kg7t/oeMs6sqlAwr85ND/9cpO3up3VxphxY0U=
github.com/jesseduffield/minimal/gitignore v0.3.3-0.20211018110810-9cde264e6b1e/go.mod h1:u60qdFGXRd36jyEXxetz0vQceQIxzI13lIo3EFUDf4I= github.com/jesseduffield/minimal/gitignore v0.3.3-0.20211018110810-9cde264e6b1e/go.mod h1:u60qdFGXRd36jyEXxetz0vQceQIxzI13lIo3EFUDf4I=
github.com/jesseduffield/yaml v2.1.0+incompatible h1:HWQJ1gIv2zHKbDYNp0Jwjlj24K8aqpFHnMCynY1EpmE= github.com/jesseduffield/yaml v2.1.0+incompatible h1:HWQJ1gIv2zHKbDYNp0Jwjlj24K8aqpFHnMCynY1EpmE=

View File

@ -125,6 +125,8 @@ type KeybindingUniversalConfig struct {
NextItemAlt string `yaml:"nextItem-alt"` NextItemAlt string `yaml:"nextItem-alt"`
PrevPage string `yaml:"prevPage"` PrevPage string `yaml:"prevPage"`
NextPage string `yaml:"nextPage"` NextPage string `yaml:"nextPage"`
ScrollLeft string `yaml:"scrollLeft"`
ScrollRight string `yaml:"scrollRight"`
GotoTop string `yaml:"gotoTop"` GotoTop string `yaml:"gotoTop"`
GotoBottom string `yaml:"gotoBottom"` GotoBottom string `yaml:"gotoBottom"`
PrevBlock string `yaml:"prevBlock"` PrevBlock string `yaml:"prevBlock"`
@ -382,6 +384,8 @@ func GetDefaultConfig() *UserConfig {
NextItemAlt: "j", NextItemAlt: "j",
PrevPage: ",", PrevPage: ",",
NextPage: ".", NextPage: ".",
ScrollLeft: "H",
ScrollRight: "L",
GotoTop: "<", GotoTop: "<",
GotoBottom: ">", GotoBottom: ">",
PrevBlock: "<left>", PrevBlock: "<left>",

View File

@ -399,6 +399,8 @@ func (gui *Gui) onViewFocusLost(oldView *gocui.View, newView *gocui.View) error
return nil return nil
} }
_ = oldView.SetOriginX(0)
if oldView == gui.Views.CommitFiles && newView != gui.Views.Main && newView != gui.Views.Secondary && newView != gui.Views.Search { if oldView == gui.Views.CommitFiles && newView != gui.Views.Main && newView != gui.Views.Secondary && newView != gui.Views.Search {
gui.resetWindowForView(gui.Views.CommitFiles) gui.resetWindowForView(gui.Views.CommitFiles)
if err := gui.deactivateContext(gui.State.Contexts.CommitFiles); err != nil { if err := gui.deactivateContext(gui.State.Contexts.CommitFiles); err != nil {

View File

@ -10,6 +10,8 @@ import (
"github.com/jesseduffield/lazygit/pkg/utils" "github.com/jesseduffield/lazygit/pkg/utils"
) )
const HORIZONTAL_SCROLL_FACTOR = 3
// these views need to be re-rendered when the screen mode changes. The commits view, // these views need to be re-rendered when the screen mode changes. The commits view,
// for example, will show authorship information in half and full screen mode. // for example, will show authorship information in half and full screen mode.
func (gui *Gui) rerenderViewsWithScreenModeDependentContent() error { func (gui *Gui) rerenderViewsWithScreenModeDependentContent() error {
@ -114,7 +116,7 @@ func (gui *Gui) linesToScrollDown(view *gocui.View) int {
func (gui *Gui) scrollUpMain() error { func (gui *Gui) scrollUpMain() error {
if gui.canScrollMergePanel() { if gui.canScrollMergePanel() {
gui.State.Panels.Merging.UserScrolling = true gui.State.Panels.Merging.UserVerticalScrolling = true
} }
return gui.scrollUpView(gui.Views.Main) return gui.scrollUpView(gui.Views.Main)
@ -122,12 +124,33 @@ func (gui *Gui) scrollUpMain() error {
func (gui *Gui) scrollDownMain() error { func (gui *Gui) scrollDownMain() error {
if gui.canScrollMergePanel() { if gui.canScrollMergePanel() {
gui.State.Panels.Merging.UserScrolling = true gui.State.Panels.Merging.UserVerticalScrolling = true
} }
return gui.scrollDownView(gui.Views.Main) return gui.scrollDownView(gui.Views.Main)
} }
func (gui *Gui) scrollLeftMain() error {
gui.scrollLeft(gui.Views.Main)
return nil
}
func (gui *Gui) scrollRightMain() error {
gui.scrollRight(gui.Views.Main)
return nil
}
func (gui *Gui) scrollLeft(view *gocui.View) {
newOriginX := utils.Max(view.OriginX()-view.InnerWidth()/HORIZONTAL_SCROLL_FACTOR, 0)
_ = view.SetOriginX(newOriginX)
}
func (gui *Gui) scrollRight(view *gocui.View) {
_ = view.SetOriginX(view.OriginX() + view.InnerWidth()/HORIZONTAL_SCROLL_FACTOR)
}
func (gui *Gui) scrollUpSecondary() error { func (gui *Gui) scrollUpSecondary() error {
return gui.scrollUpView(gui.Views.Secondary) return gui.scrollUpView(gui.Views.Secondary)
} }

View File

@ -145,9 +145,9 @@ type LblPanelState struct {
type MergingPanelState struct { type MergingPanelState struct {
*mergeconflicts.State *mergeconflicts.State
// UserScrolling tells us if the user has started scrolling through the file themselves // UserVerticalScrolling tells us if the user has started scrolling through the file themselves
// in which case we won't auto-scroll to a conflict. // in which case we won't auto-scroll to a conflict.
UserScrolling bool UserVerticalScrolling bool
} }
type filePanelState struct { type filePanelState struct {
@ -403,8 +403,8 @@ func (gui *Gui) resetState(filterPath string, reuseState bool) {
Menu: &menuPanelState{listPanelState: listPanelState{SelectedLineIdx: 0}, OnPress: nil}, Menu: &menuPanelState{listPanelState: listPanelState{SelectedLineIdx: 0}, OnPress: nil},
Suggestions: &suggestionsPanelState{listPanelState: listPanelState{SelectedLineIdx: 0}}, Suggestions: &suggestionsPanelState{listPanelState: listPanelState{SelectedLineIdx: 0}},
Merging: &MergingPanelState{ Merging: &MergingPanelState{
State: mergeconflicts.NewState(), State: mergeconflicts.NewState(),
UserScrolling: false, UserVerticalScrolling: false,
}, },
}, },
Ptmx: nil, Ptmx: nil,

View File

@ -1426,6 +1426,20 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Modifier: gocui.ModNone, Modifier: gocui.ModNone,
Handler: gui.scrollDownMain, Handler: gui.scrollDownMain,
}, },
{
ViewName: "main",
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY), string(MAIN_MERGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.ScrollLeft),
Handler: gui.scrollLeftMain,
Description: gui.Tr.LcScrollLeft,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY), string(MAIN_MERGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.ScrollRight),
Handler: gui.scrollRightMain,
Description: gui.Tr.LcScrollRight,
},
{ {
ViewName: "main", ViewName: "main",
Contexts: []string{string(MAIN_STAGING_CONTEXT_KEY)}, Contexts: []string{string(MAIN_STAGING_CONTEXT_KEY)},

View File

@ -174,7 +174,7 @@ func (gui *Gui) focusSelection(state *LblPanelState) error {
newOrigin := state.CalculateOrigin(origin, bufferHeight) newOrigin := state.CalculateOrigin(origin, bufferHeight)
gui.g.Update(func(*gocui.Gui) error { gui.g.Update(func(*gocui.Gui) error {
if err := stagingView.SetOrigin(0, newOrigin); err != nil { if err := stagingView.SetOriginY(newOrigin); err != nil {
return err return err
} }

View File

@ -30,6 +30,8 @@ type IListContext interface {
OnRender() error OnRender() error
handlePrevLine() error handlePrevLine() error
handleNextLine() error handleNextLine() error
handleScrollLeft() error
handleScrollRight() error
handleLineChange(change int) error handleLineChange(change int) error
handleNextPage() error handleNextPage() error
handleGotoTop() error handleGotoTop() error
@ -69,7 +71,7 @@ func (self *ListContext) FocusLine() {
} }
// we need a way of knowing whether we've rendered to the view yet. // we need a way of knowing whether we've rendered to the view yet.
view.FocusPoint(0, self.GetPanelState().GetSelectedLineIdx()) view.FocusPoint(view.OriginX(), self.GetPanelState().GetSelectedLineIdx())
if self.RenderSelection { if self.RenderSelection {
_, originY := view.Origin() _, originY := view.Origin()
displayStrings := self.GetDisplayStrings(originY, view.InnerHeight()) displayStrings := self.GetDisplayStrings(originY, view.InnerHeight())
@ -117,6 +119,13 @@ func (self *ListContext) HandleFocusLost() error {
return self.OnFocusLost() return self.OnFocusLost()
} }
view, err := self.Gui.g.View(self.ViewName)
if err != nil {
return nil
}
_ = view.SetOriginX(0)
return nil return nil
} }
@ -150,8 +159,44 @@ func (self *ListContext) handleNextLine() error {
return self.handleLineChange(1) return self.handleLineChange(1)
} }
func (self *ListContext) handleScrollLeft() error {
if self.ignoreKeybinding() {
return nil
}
// get the view, move the origin
view, err := self.Gui.g.View(self.ViewName)
if err != nil {
return nil
}
self.Gui.scrollLeft(view)
return self.HandleFocus()
}
func (self *ListContext) handleScrollRight() error {
if self.ignoreKeybinding() {
return nil
}
// get the view, move the origin
view, err := self.Gui.g.View(self.ViewName)
if err != nil {
return nil
}
self.Gui.scrollRight(view)
return self.HandleFocus()
}
func (self *ListContext) ignoreKeybinding() bool {
return !self.Gui.isPopupPanel(self.ViewName) && self.Gui.popupPanelFocused()
}
func (self *ListContext) handleLineChange(change int) error { func (self *ListContext) handleLineChange(change int) error {
if !self.Gui.isPopupPanel(self.ViewName) && self.Gui.popupPanelFocused() { if self.ignoreKeybinding() {
return nil return nil
} }
@ -195,7 +240,7 @@ func (self *ListContext) handlePrevPage() error {
} }
func (self *ListContext) handleClick() error { func (self *ListContext) handleClick() error {
if !self.Gui.isPopupPanel(self.ViewName) && self.Gui.popupPanelFocused() { if self.ignoreKeybinding() {
return nil return nil
} }

View File

@ -402,6 +402,8 @@ func (gui *Gui) getListContextKeyBindings() []*Binding {
{ViewName: listContext.GetViewName(), Tag: "navigation", Contexts: []string{string(listContext.GetKey())}, Key: gui.getKey(keybindingConfig.Universal.GotoTop), Modifier: gocui.ModNone, Handler: listContext.handleGotoTop, Description: gui.Tr.LcGotoTop}, {ViewName: listContext.GetViewName(), Tag: "navigation", Contexts: []string{string(listContext.GetKey())}, Key: gui.getKey(keybindingConfig.Universal.GotoTop), Modifier: gocui.ModNone, Handler: listContext.handleGotoTop, Description: gui.Tr.LcGotoTop},
{ViewName: listContext.GetViewName(), Tag: "navigation", Contexts: []string{string(listContext.GetKey())}, Key: gocui.MouseWheelDown, Modifier: gocui.ModNone, Handler: listContext.handleNextLine}, {ViewName: listContext.GetViewName(), Tag: "navigation", Contexts: []string{string(listContext.GetKey())}, Key: gocui.MouseWheelDown, Modifier: gocui.ModNone, Handler: listContext.handleNextLine},
{ViewName: listContext.GetViewName(), Contexts: []string{string(listContext.GetKey())}, Key: gocui.MouseLeft, Modifier: gocui.ModNone, Handler: listContext.handleClick}, {ViewName: listContext.GetViewName(), Contexts: []string{string(listContext.GetKey())}, Key: gocui.MouseLeft, Modifier: gocui.ModNone, Handler: listContext.handleClick},
{ViewName: listContext.GetViewName(), Tag: "navigation", Contexts: []string{string(listContext.GetKey())}, Key: gui.getKey(keybindingConfig.Universal.ScrollLeft), Modifier: gocui.ModNone, Handler: listContext.handleScrollLeft},
{ViewName: listContext.GetViewName(), Tag: "navigation", Contexts: []string{string(listContext.GetKey())}, Key: gui.getKey(keybindingConfig.Universal.ScrollRight), Modifier: gocui.ModNone, Handler: listContext.handleScrollRight},
}...) }...)
// the commits panel needs to lazyload things so it has a couple of its own handlers // the commits panel needs to lazyload things so it has a couple of its own handlers

View File

@ -203,7 +203,7 @@ func (gui *Gui) catSelectedFile() (string, error) {
} }
func (gui *Gui) scrollToConflict() error { func (gui *Gui) scrollToConflict() error {
if gui.State.Panels.Merging.UserScrolling { if gui.State.Panels.Merging.UserVerticalScrolling {
return nil return nil
} }
@ -315,5 +315,5 @@ func (gui *Gui) withMergeConflictLock(f func() error) error {
} }
func (gui *Gui) takeOverMergeConflictScrolling() { func (gui *Gui) takeOverMergeConflictScrolling() {
gui.State.Panels.Merging.UserScrolling = false gui.State.Panels.Merging.UserVerticalScrolling = false
} }

View File

@ -323,6 +323,7 @@ func (gui *Gui) globalOptionsMap() map[string]string {
gui.getKeyDisplay(keybindingConfig.Universal.Quit): gui.Tr.LcQuit, gui.getKeyDisplay(keybindingConfig.Universal.Quit): gui.Tr.LcQuit,
gui.getKeyDisplay(keybindingConfig.Universal.OptionMenu): gui.Tr.LcMenu, gui.getKeyDisplay(keybindingConfig.Universal.OptionMenu): gui.Tr.LcMenu,
fmt.Sprintf("%s-%s", gui.getKeyDisplay(keybindingConfig.Universal.JumpToBlock[0]), gui.getKeyDisplay(keybindingConfig.Universal.JumpToBlock[len(keybindingConfig.Universal.JumpToBlock)-1])): gui.Tr.LcJump, fmt.Sprintf("%s-%s", gui.getKeyDisplay(keybindingConfig.Universal.JumpToBlock[0]), gui.getKeyDisplay(keybindingConfig.Universal.JumpToBlock[len(keybindingConfig.Universal.JumpToBlock)-1])): gui.Tr.LcJump,
fmt.Sprintf("%s/%s", gui.getKeyDisplay(keybindingConfig.Universal.ScrollLeft), gui.getKeyDisplay(keybindingConfig.Universal.ScrollRight)): gui.Tr.LcScrollLeftRight,
} }
} }

View File

@ -271,6 +271,9 @@ type TranslationSet struct {
LcStashOptions string LcStashOptions string
NotARepository string NotARepository string
LcJump string LcJump string
LcScrollLeftRight string
LcScrollLeft string
LcScrollRight string
DiscardPatch string DiscardPatch string
DiscardPatchConfirm string DiscardPatchConfirm string
CantPatchWhileRebasingError string CantPatchWhileRebasingError string
@ -802,6 +805,9 @@ func englishTranslationSet() TranslationSet {
LcStashOptions: "Stash options", LcStashOptions: "Stash options",
NotARepository: "Error: must be run inside a git repository", NotARepository: "Error: must be run inside a git repository",
LcJump: "jump to panel", LcJump: "jump to panel",
LcScrollLeftRight: "scroll left/right",
LcScrollLeft: "scroll left",
LcScrollRight: "scroll right",
DiscardPatch: "Discard Patch", DiscardPatch: "Discard Patch",
DiscardPatchConfirm: "You can only build a patch from one commit/stash-entry at a time. Discard current patch?", DiscardPatchConfirm: "You can only build a patch from one commit/stash-entry at a time. Discard current patch?",
CantPatchWhileRebasingError: "You cannot build a patch or run patch commands while in a merging or rebasing state", CantPatchWhileRebasingError: "You cannot build a patch or run patch commands while in a merging or rebasing state",

View File

@ -475,9 +475,33 @@ func (v *View) SetOrigin(x, y int) error {
return nil return nil
} }
func (v *View) SetOriginX(x int) error {
if x < 0 {
return ErrInvalidPoint
}
v.ox = x
return nil
}
func (v *View) SetOriginY(y int) error {
if y < 0 {
return ErrInvalidPoint
}
v.oy = y
return nil
}
// Origin returns the origin position of the view. // Origin returns the origin position of the view.
func (v *View) Origin() (x, y int) { func (v *View) Origin() (x, y int) {
return v.ox, v.oy return v.OriginX(), v.OriginY()
}
func (v *View) OriginX() int {
return v.ox
}
func (v *View) OriginY() int {
return v.oy
} }
// SetWritePos sets the write position of the view's internal buffer. // SetWritePos sets the write position of the view's internal buffer.

2
vendor/modules.txt vendored
View File

@ -161,7 +161,7 @@ github.com/jesseduffield/go-git/v5/utils/merkletrie/filesystem
github.com/jesseduffield/go-git/v5/utils/merkletrie/index github.com/jesseduffield/go-git/v5/utils/merkletrie/index
github.com/jesseduffield/go-git/v5/utils/merkletrie/internal/frame github.com/jesseduffield/go-git/v5/utils/merkletrie/internal/frame
github.com/jesseduffield/go-git/v5/utils/merkletrie/noder github.com/jesseduffield/go-git/v5/utils/merkletrie/noder
# github.com/jesseduffield/gocui v0.3.1-0.20211102081536-e4eee64f4d13 # github.com/jesseduffield/gocui v0.3.1-0.20211102093457-be3a05cf7131
## explicit ## explicit
github.com/jesseduffield/gocui github.com/jesseduffield/gocui
# github.com/jesseduffield/minimal/gitignore v0.3.3-0.20211018110810-9cde264e6b1e # github.com/jesseduffield/minimal/gitignore v0.3.3-0.20211018110810-9cde264e6b1e