mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-08-28 02:24:49 -05:00
The one behaviour that made scrolling the selection into view opt-in in the first place — a background refresh must not yank the view back to a selection the user scrolled away from — has never been covered by a test. It's about to become the one case that the automatic scrolling has to suppress, so cover it first. Getting there needs two things from the test harness: mouse wheel events, which are the only way to scroll a list panel without moving the selection, and a way to trigger a background refresh. The periodic routine that issues it is turned off in tests, and turning it on would mean waiting for its timer and hoping it fires while we're looking, so drive the refresh directly instead. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package ui
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/config"
|
|
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
|
)
|
|
|
|
var BackgroundRefreshKeepsScrollPosition = NewIntegrationTest(NewIntegrationTestArgs{
|
|
Description: "A background refresh doesn't scroll the selection back into view",
|
|
ExtraCmdArgs: []string{},
|
|
Skip: false,
|
|
Width: 120,
|
|
Height: 30,
|
|
SetupConfig: func(config *config.AppConfig) {},
|
|
SetupRepo: func(shell *Shell) {
|
|
shell.EmptyCommit("initial commit")
|
|
for i := range 20 {
|
|
shell.CreateFile(fmt.Sprintf("file%02d", i), "")
|
|
}
|
|
},
|
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
|
t.Views().Files().
|
|
Focus().
|
|
SelectNextItem().
|
|
SelectedLine(Contains("file00")).
|
|
// Scroll the selection out of view with the mouse wheel
|
|
ScrollWheelDown().
|
|
ScrollWheelDown().
|
|
OriginY(4).
|
|
Tap(func() {
|
|
t.Shell().CreateFile("aaa", "")
|
|
t.RefreshInBackground()
|
|
}).
|
|
// The new file sorts before the selected one, so the selection has
|
|
// moved down a line; the view must stay where the user left it though
|
|
SelectedLineIdx(2).
|
|
OriginY(4)
|
|
},
|
|
})
|