1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2026-01-26 01:41:35 +03:00

Avoid scrolling the selection into view on refresh

It is possible to scroll the selection out of view using the mouse wheel; after
doing this, it would sometimes scroll into view by itself again, for example
when a background fetch occurred. In the files panel this would even happen
every 10s with every regular files refresh.

Fix this by adding a scrollIntoView parameter to HandleFocus, which is false by
default, and is only set to true from controllers that change the selection.
This commit is contained in:
Stefan Haller
2025-12-22 16:08:29 +01:00
parent 37bc0dfc44
commit efd4298b5e
15 changed files with 35 additions and 26 deletions

View File

@@ -262,7 +262,7 @@ func (v *View) SelectSearchResult(index int) error {
y := v.searcher.searchPositions[index].Y
v.FocusPoint(v.ox, y)
v.FocusPoint(v.ox, y, true)
if v.searcher.onSelectItem != nil {
return v.searcher.onSelectItem(y, index, itemCount)
}
@@ -325,14 +325,17 @@ func (v *View) IsSearching() bool {
return v.searcher.searchString != ""
}
func (v *View) FocusPoint(cx int, cy int) {
func (v *View) FocusPoint(cx int, cy int, scrollIntoView bool) {
lineCount := len(v.lines)
if cy < 0 || cy > lineCount {
return
}
height := v.InnerHeight()
v.oy = calculateNewOrigin(cy, v.oy, lineCount, height)
if scrollIntoView {
height := v.InnerHeight()
v.oy = calculateNewOrigin(cy, v.oy, lineCount, height)
}
v.cx = cx
v.cy = cy - v.oy
}