1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-11-25 22:32:13 +02:00

Merge pull request #2608 from stefanhaller/allow-selected-line-outside-view

Allow the selected line of a list view to be outside the visible area
This commit is contained in:
Stefan Haller
2023-05-13 12:29:17 +02:00
committed by GitHub
6 changed files with 7 additions and 19 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() { return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.COMMITS}, Then: func() {
self.c.Contexts().LocalCommits.SetSelectedLineIdx(0) 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 scrollHeight := self.c.UserConfig.Gui.ScrollHeight
self.context.GetViewTrait().ScrollUp(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 return nil
} }
@@ -67,19 +61,9 @@ func (self *ListController) HandleScrollDown() error {
scrollHeight := self.c.UserConfig.Gui.ScrollHeight scrollHeight := self.c.UserConfig.Gui.ScrollHeight
self.context.GetViewTrait().ScrollDown(scrollHeight) self.context.GetViewTrait().ScrollDown(scrollHeight)
if !self.isSelectedLineInViewPort() {
return self.handleLineChange(scrollHeight)
}
return nil 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 { func (self *ListController) scrollHorizontal(scrollFunc func()) error {
scrollFunc() scrollFunc()

View File

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

View File

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

View File

@@ -18,10 +18,12 @@ var SelectFile = NewIntegrationTest(NewIntegrationTestArgs{
t.Views().Commits(). t.Views().Commits().
Focus(). Focus().
Lines( Lines(
Contains(`only filterFile`).IsSelected(), Contains(`none of the two`).IsSelected(),
Contains(`only filterFile`),
Contains(`only otherFile`), Contains(`only otherFile`),
Contains(`both files`), Contains(`both files`),
). ).
SelectNextItem().
PressEnter() PressEnter()
// when you click into the commit itself, you see all files from that commit // when you click into the commit itself, you see all files from that commit

View File

@@ -14,6 +14,8 @@ func commonSetup(shell *Shell) {
shell.UpdateFileAndAdd("filterFile", "new filterFile content") shell.UpdateFileAndAdd("filterFile", "new filterFile content")
shell.Commit("only filterFile") shell.Commit("only filterFile")
shell.EmptyCommit("none of the two")
} }
func postFilterTest(t *TestDriver) { func postFilterTest(t *TestDriver) {