Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 26 additions & 38 deletions internal/tui/select_raw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,24 +506,34 @@ func dragEveryFrameFollow(t *testing.T, h *rawHarness, state string, following b
dragFrame(t, h, state+" release", sgrLeftRelease(25, 6), base)
}

func TestSelectionDragEveryFrameMiddle(t *testing.T) {
h := newRawHarness(t, 200)
for i := 0; i < 6; i++ {
h.in.WriteString(sgrWheelUp(5, 20))
h.settle()
}
// Wheel lines clamp at the top, so the middle is reached by
// pressing the mouse wheel up repeatedly; if it never moves the
// precondition fails loudly.
deadline := time.Now().Add(500 * time.Millisecond)
// scrollUpNTimes scrolls the view up by sending n wheel-up events,
// waiting for each one to settle on screen before sending the next.
// waitFor reads the settled screen grid, not a quiet output window:
// a wheel-up can be queued while the program is still rendering,
// and settle() alone cannot tell a finished program from a busy
// one. Returns the first visible content line after the last scroll.
// The caller asserts its own precondition (middle, above bottom).
func scrollUpNTimes(t *testing.T, h *rawHarness, n int) int {
t.Helper()
base := firstContentLine(h.screenGridNow().gridLines())
for time.Now().Before(deadline) && base <= 0 {
time.Sleep(50 * time.Millisecond)
h.settle()
if base < 0 {
t.Fatalf("no content line visible before wheel-up (first = %d)", base)
}
for i := 0; i < n; i++ {
before := base
h.in.WriteString(sgrWheelUp(5, 20))
h.settle()
h.waitFor("a wheel-up scrolls up", func() bool {
got := firstContentLine(h.screenGridNow().gridLines())
return got >= 0 && got < before
})
base = firstContentLine(h.screenGridNow().gridLines())
}
return base
}

func TestSelectionDragEveryFrameMiddle(t *testing.T) {
h := newRawHarness(t, 200)
base := scrollUpNTimes(t, h, 6)
if base <= 0 {
t.Fatalf("wheel-up did not scroll to the middle (first visible = %d)", base)
}
Expand All @@ -533,11 +543,7 @@ func TestSelectionDragEveryFrameMiddle(t *testing.T) {

func TestSelectionDragEveryFrameOneScreenAboveBottom(t *testing.T) {
h := newRawHarness(t, 200)
for i := 0; i < 3; i++ {
h.in.WriteString(sgrWheelUp(5, 20))
h.settle()
}
base := firstContentLine(h.screenGridNow().gridLines())
base := scrollUpNTimes(t, h, 3)
if base <= 0 {
t.Fatalf("wheel-up did not scroll above the bottom (first visible = %d)", base)
}
Expand Down Expand Up @@ -624,25 +630,7 @@ func TestOSC52EscapeCanBeCoalescedAway(t *testing.T) {
// followBottom and the offset). Raw SGR bytes, every frame checked.
func TestSelectionWheelMidDrag(t *testing.T) {
h := newRawHarness(t, 200)
for i := 0; i < 6; i++ {
h.in.WriteString(sgrWheelUp(5, 20))
h.settle()
}
// Poll until the view reaches the middle BEFORE capturing base:
// a setup wheel-up can land late (one settle read the old frame
// while the program was still rendering), so a base captured
// without settling to the middle is stale and every later
// dragFrame assertion compares against the wrong frame. This is
// the pattern TestSelectionDragEveryFrameMiddle already uses.
deadline := time.Now().Add(500 * time.Millisecond)
base := firstContentLine(h.screenGridNow().gridLines())
for time.Now().Before(deadline) && base <= 0 {
time.Sleep(50 * time.Millisecond)
h.settle()
h.in.WriteString(sgrWheelUp(5, 20))
h.settle()
base = firstContentLine(h.screenGridNow().gridLines())
}
base := scrollUpNTimes(t, h, 6)
if base <= 0 {
t.Fatalf("did not scroll to the middle (first visible = %d)", base)
}
Expand Down
Loading