v0.1.0 47aaa0f

edit_pointer_test.go RawHistoryFolder

1package ui
2
3import (
4	"testing"
5	"time"
6
7	"github.com/bnema/nefergui/internal/css"
8	"github.com/bnema/nefergui/internal/text"
9)
10
11func TestPointerTextSelection(t *testing.T) {
12	catalog, err := text.Load(text.DirectorySource("../../testdata/fonts"))
13	if err != nil {
14		t.Fatal(err)
15	}
16	r := newRuntime()
17	r.setTextEngine(text.NewEngine(catalog))
18	r.styles = css.Compile(css.UA(), css.Parse(`input, textarea { width: 240px; height: 32px; font-size: 16px; }`))
19	value := "aé word"
20	view := func(f *Frame) { f.Root().Input("edit", &value, Key("edit")) }
21	r.Build(view)
22	n := r.output.Tree.Children[0]
23	id := n.ID
24	bs := textBoundaries(value, n, r.output.Display)
25	if len(bs) == 0 || len(bs[0]) < 3 {
26		t.Fatalf("no text clusters: %+v", bs)
27	}
28	x := func(b int) float64 {
29		for _, v := range bs[0] {
30			if v.byteOffset == b {
31				return v.x
32			}
33		}
34		t.Fatalf("no boundary %d: %+v", b, bs)
35		return 0
36	}
37	y := n.Content.Y + 1
38	at := time.Unix(20, 0)
39	press := func(px float64, when time.Time, shift bool) {
40		r.route(platformInput{Kind: "press", Button: pointerPrimary, X: px, Y: y, Time: when, Shift: shift})
41		r.Build(view)
42	}
43	release := func() { r.route(platformInput{Kind: "release", Button: pointerPrimary, X: 0, Y: y}); r.Build(view) }
44	press(x(3), at, false)
45	if got := r.edits[id].Cursor; got != 3 {
46		t.Fatalf("UTF-8 boundary got %d want 3: %+v content=%+v", got, bs, n.Content)
47	}
48	r.route(platformInput{Kind: "motion", X: x(0), Y: y})
49	r.Build(view)
50	if a, b := r.edits[id].Range(); a != 0 || b != 3 {
51		t.Fatalf("drag selection %d:%d", a, b)
52	}
53	release()
54	press(x(8)-0.01, at.Add(time.Second), true)
55	if a, b := r.edits[id].Range(); a != 3 || b != 8 {
56		t.Fatalf("shift selection %d:%d", a, b)
57	}
58	release()
59	press(x(5), at.Add(2*time.Second), false)
60	release()
61	press(x(5), at.Add(2*time.Second+300*time.Millisecond), false)
62	if a, b := r.edits[id].Range(); a != 4 || b != 8 {
63		t.Fatalf("double word selection %d:%d", a, b)
64	}
65	release()
66	// A word start used to include the previous segment too.
67	press(x(4), at.Add(3*time.Second), false)
68	release()
69	press(x(4), at.Add(3*time.Second+200*time.Millisecond), false)
70	if a, b := r.edits[id].Range(); a != 4 || b != 8 {
71		t.Fatalf("boundary word selection %d:%d", a, b)
72	}
73}

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