v0.6.1 aa12db3

paste_test.go RawHistoryFolder

1package ui
2
3import (
4	"context"
5	"errors"
6	"testing"
7
8	"github.com/bnema/nefergui/internal/edit"
9	"github.com/stretchr/testify/mock"
10)
11
12func TestAsyncPasteFrameAndCancellation(t *testing.T) {
13	r := newRuntime()
14	c := NewMockAsyncClipboard(t) // synchronous ReadText is not expected
15	var contexts []context.Context
16	var callbacks []func([]byte, error)
17	c.EXPECT().ReadTextAsync(mock.Anything, edit.MaxClipboardBytes, mock.Anything).
18		RunAndReturn(func(ctx context.Context, _ int, deliver func([]byte, error)) error {
19			contexts = append(contexts, ctx)
20			callbacks = append(callbacks, deliver)
21			return nil
22		})
23	r.clipboard = asyncClipboard{c}
24	name := ""
25	var changed bool
26	var diagnostics []string
27	view := func(f *Frame) {
28		changed = f.Root().Input("name", &name, Key("name")).Changed()
29		diagnostics = f.Diagnostics()
30	}
31	r.Build(view)
32	paste := func() {
33		r.Queue(inputEvent{Target: r.Target(0), Kind: "edit-key", Text: "v", Ctrl: true})
34		if !r.Build(view) {
35			t.Fatal("no frame")
36		}
37		if changed {
38			t.Fatal("paste changed before delivery")
39		}
40	}
41	paste()
42	paste()
43	if contexts[0].Err() != context.Canceled {
44		t.Fatal("old read not cancelled")
45	}
46	callbacks[0]([]byte("old"), nil)
47	callbacks[1]([]byte("Ada"), nil)
48	if !r.Build(view) || !changed || name != "Ada" {
49		t.Fatalf("paste: changed=%v value=%q", changed, name)
50	}
51	paste()
52	callbacks[2]([]byte{0xff}, nil)
53	r.Build(view)
54	if name != "Ada" || changed {
55		t.Fatal("invalid UTF-8 accepted")
56	}
57	paste()
58	callbacks[3](make([]byte, edit.MaxClipboardBytes+1), nil)
59	r.Build(view)
60	if name != "Ada" || changed {
61		t.Fatal("oversize accepted")
62	}
63	paste()
64	callbacks[4](nil, errors.New("transfer failed"))
65	r.Build(view)
66	if debugDiagnostics && len(diagnostics) != 1 {
67		t.Fatalf("missing error diagnostic: %v", diagnostics)
68	}
69}

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 1

Tags 12

↑↓ moveenter openesc close