copy_scroll_animation_test.go RawHistoryFolder

1package daemon
2
3import (
4	"testing"
5	"time"
6
7	"github.com/bnema/vev/internal/domain"
8	"github.com/stretchr/testify/require"
9)
10
11func TestCopyScrollAnimationEasesAndPreservesDistance(t *testing.T) {
12	for _, burst := range []int{1, 6} {
13		t.Run(map[int]string{1: "notch", 6: "burst"}[burst], func(t *testing.T) {
14			f := newPerformanceFixture(t, performanceConfig{size: domain.Size{Cols: 80, Rows: 24}, panes: 1, historyRows: 200})
15			f.d.enterCopyMode(f.sess, f.ac)
16			f.d.copyWheel(f.sess, f.ac, -50)
17			f.ac.ackOutputState(f.ac.output.currentEpoch(), f.ac.output.next)
18			clock := newCoordinatorMockClock(t, 16)
19			f.d.clock = clock.clock
20			emitted := make(chan struct{}, 16)
21			f.ac.renderStages.emit = func() { emitted <- struct{}{} }
22			await := func() {
23				select {
24				case <-emitted:
25				case <-time.After(time.Second):
26					t.Fatal("scroll frame not emitted")
27				}
28				// Wait for publication and capture the ACK coordinates under
29				// the same lock that protects the in-flight output transaction.
30				f.ac.sendMu.Lock()
31				epoch, state := f.ac.output.currentEpoch(), f.ac.output.next
32				f.ac.sendMu.Unlock()
33				f.ac.ackOutputState(epoch, state)
34			}
35			rt := f.ac.overlays
36			start := rt.copyMode.ViewportTop
37			for range burst {
38				f.d.smoothCopyWheel(f.sess, f.ac, -3)
39			}
40			await()
41			require.Equal(t, start-1, rt.copyMode.ViewportTop, "first row responds immediately; bursts wait for the next frame")
42			for frame := 0; ; frame++ {
43				rt.copyMu.Lock()
44				pending := rt.copyScroll.remaining
45				rt.copyMu.Unlock()
46				if pending == 0 {
47					break
48				}
49				require.Less(t, frame, 16, "animation must settle")
50				timer := awaitCoordinatorScheduledTimer(t, clock)
51				require.Equal(t, copyScrollFrame, timer.duration)
52				timer.ch <- time.Time{}
53				await()
54			}
55			require.Equal(t, start-3*burst, rt.copyMode.ViewportTop)
56		})
57	}
58}
59
60func TestCopyScrollAnimationReversalAndCancellation(t *testing.T) {
61	f := newPerformanceFixture(t, performanceConfig{size: domain.Size{Cols: 80, Rows: 24}, panes: 1, historyRows: 200})
62	f.d.enterCopyMode(f.sess, f.ac)
63	f.d.copyWheel(f.sess, f.ac, -50)
64	f.ac.ackOutputState(f.ac.output.currentEpoch(), f.ac.output.next)
65	clock := newCoordinatorMockClock(t, 8)
66	f.d.clock = clock.clock
67	rt := f.ac.overlays
68	start := rt.copyMode.ViewportTop
69	f.d.smoothCopyWheel(f.sess, f.ac, -3)
70	old := awaitCoordinatorScheduledTimer(t, clock)
71	f.d.smoothCopyWheel(f.sess, f.ac, 3)
72	require.Equal(t, start, rt.copyMode.ViewportTop, "reversal responds without finishing the old tail")
73	select {
74	case <-old.stopped:
75	default:
76		t.Fatal("old direction timer not canceled")
77	}
78	current := awaitCoordinatorScheduledTimer(t, clock)
79	rt.copyMu.Lock()
80	rt.invalidateCopyPointerLocked(true)
81	require.Zero(t, rt.copyScroll.remaining)
82	require.Nil(t, rt.copyScroll.timer.timer)
83	rt.copyMu.Unlock()
84	select {
85	case <-current.stopped:
86	default:
87		t.Fatal("pointer lifecycle must stop inertia")
88	}
89}
90
91func TestCopyScrollAnimationTailDeadline(t *testing.T) {
92	f := newPerformanceFixture(t, performanceConfig{size: domain.Size{Cols: 80, Rows: 24}, panes: 1, historyRows: 200})
93	f.d.enterCopyMode(f.sess, f.ac)
94	clock := newCoordinatorMockClock(t, 8)
95	f.d.clock = clock.clock
96	rt := f.ac.overlays
97	rt.copyMu.Lock()
98	start := rt.copyMode.ViewportTop
99	rt.copyScroll.remaining = -60
100	rt.copyScroll.lastInput = time.Time{}.Add(-copyScrollTail)
101	changed, exit := f.d.advanceCopyScrollLocked(f.sess, f.ac)
102	require.True(t, changed)
103	require.False(t, exit)
104	require.Equal(t, start-60, rt.copyMode.ViewportTop)
105	require.Zero(t, rt.copyScroll.remaining)
106	require.Nil(t, rt.copyScroll.timer.timer)
107	rt.copyMu.Unlock()
108}
109
110func TestCopyScrollReducedMotionAndKeyboardCancellation(t *testing.T) {
111	f := newPerformanceFixture(t, performanceConfig{size: domain.Size{Cols: 80, Rows: 24}, panes: 1, historyRows: 200})
112	f.d.enterCopyMode(f.sess, f.ac)
113	f.ac.ackOutputState(f.ac.output.currentEpoch(), f.ac.output.next)
114	clock := newCoordinatorMockClock(t, 8)
115	f.d.clock = clock.clock
116	updateRuntimeConfig(f.d, func(rc *runtimeConfig) { rc.copy = domain.CopyConfig{ReduceMotion: true} })
117	rt := f.ac.overlays
118	start := rt.copyMode.ViewportTop
119	f.d.smoothCopyWheel(f.sess, f.ac, -3)
120	require.Equal(t, start-3, rt.copyMode.ViewportTop)
121	require.Empty(t, clock.timers, "reduced motion must not arm an animation")
122	updateRuntimeConfig(f.d, func(rc *runtimeConfig) { rc.copy = domain.CopyConfig{} })
123	f.d.smoothCopyWheel(f.sess, f.ac, -3)
124	timer := awaitCoordinatorScheduledTimer(t, clock)
125	require.True(t, rt.HandleInput(f.d, []byte("k")))
126	rt.copyMu.Lock()
127	require.Zero(t, rt.copyScroll.remaining)
128	require.Nil(t, rt.copyScroll.timer.timer)
129	rt.copyMu.Unlock()
130	select {
131	case <-timer.stopped:
132	default:
133		t.Fatal("keyboard navigation must cancel inertia")
134	}
135}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 12

Tags 11

↑↓ moveenter openesc close