v0.1.0 47aaa0f

paste_test.go RawHistoryFolder

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

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