1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-03-17 21:18:31 +02:00

Allow the selected line of a list view to be outside the visible area

I don't see a reason why this restriction to have the selection be always
visible was necessary. Removing it has two benefits:

1. Scrolling a list view doesn't change the selection. A common scenario: you
   look at one of the commits of your current branch; you want to see the how
   many'th commit this is, but the beginning of the branch is scrolled off the
   bottom of the commits panel. You scroll down to find the beginning of your
   branch, but this changes the selection and shows a different commit now - not
   what you want.

2. It is possible to scroll a panel that is not the current one without changing
   the focus to it. That's how windows in other GUIs usually behave.
This commit is contained in:
Stefan Haller 2023-05-06 14:02:14 +02:00
parent 595c7ee73e
commit e5dd4d3110
4 changed files with 2 additions and 18 deletions

View File

@ -74,5 +74,6 @@ func (self *FilteringMenuAction) setFiltering(path string) error {
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.COMMITS}, Then: func() {
self.c.Contexts().LocalCommits.SetSelectedLineIdx(0)
self.c.Contexts().LocalCommits.FocusLine()
}})
}

View File

@ -54,12 +54,6 @@ func (self *ListController) HandleScrollUp() error {
scrollHeight := self.c.UserConfig.Gui.ScrollHeight
self.context.GetViewTrait().ScrollUp(scrollHeight)
// we only need to do a line change if our line has been pushed out of the viewport, because
// at the moment much logic depends on the selected line always being visible
if !self.isSelectedLineInViewPort() {
return self.handleLineChange(-scrollHeight)
}
return nil
}
@ -67,19 +61,9 @@ func (self *ListController) HandleScrollDown() error {
scrollHeight := self.c.UserConfig.Gui.ScrollHeight
self.context.GetViewTrait().ScrollDown(scrollHeight)
if !self.isSelectedLineInViewPort() {
return self.handleLineChange(scrollHeight)
}
return nil
}
func (self *ListController) isSelectedLineInViewPort() bool {
selectedLineIdx := self.context.GetList().GetSelectedLineIdx()
startIdx, length := self.context.GetViewTrait().ViewPortYBounds()
return selectedLineIdx >= startIdx && selectedLineIdx < startIdx+length
}
func (self *ListController) scrollHorizontal(scrollFunc func()) error {
scrollFunc()

View File

@ -187,6 +187,7 @@ func (self *StashController) handleRenameStashEntry(stashEntry *models.StashEntr
return err
}
self.context().SetSelectedLineIdx(0) // Select the renamed stash
self.context().FocusLine()
return nil
},
})

View File

@ -131,8 +131,6 @@ func (gui *Gui) layout(g *gocui.Gui) error {
continue
}
listContext.FocusLine()
view.SelBgColor = theme.GocuiSelectedLineBgColor
// I doubt this is expensive though it's admittedly redundant after the first render