main bcc9a45

edit_paint_test.go RawHistoryFolder

1package ui
2
3import (
4	"github.com/bnema/nefergui/internal/css"
5	"github.com/bnema/nefergui/internal/text"
6	"math"
7	"testing"
8)
9
10func TestEditorVisualSelectionAndCaret(t *testing.T) {
11	catalog, err := text.Load(text.DirectorySource("../../testdata/fonts"))
12	if err != nil {
13		t.Fatal(err)
14	}
15	for _, tc := range []struct {
16		name, value string
17		start, end  int
18	}{{"latin", "abc def", 1, 5}, {"arabic", "مرحبا", 0, len("مرحبا")}} {
19		t.Run(tc.name, func(t *testing.T) {
20			r := newRuntime()
21			r.setTextEngine(text.NewEngine(catalog))
22			r.styles = css.Compile(css.UA(), css.Parse(`input {width:240px;height:24px;font-size:16px}`))
23			value := tc.value
24			view := func(f *Frame) { f.Root().Input("label", &value) }
25			r.Build(view)
26			r.route(key("Tab"))
27			r.Build(view)
28			s := r.edits[idKey(r.Target(0))]
29			s.Select(tc.start, tc.end)
30			r.Redraw()
31			r.Build(view)
32			count := 0
33			minX, maxX := math.Inf(1), math.Inf(-1)
34			caret := 0
35			for _, c := range r.output.Display {
36				if c.ID != idKey(r.Target(0)) {
37					continue
38				}
39				if c.Op == "selection" {
40					count++
41					minX = math.Min(minX, c.Rect.X)
42					maxX = math.Max(maxX, c.Rect.X+c.Rect.W)
43					if c.Rect.W <= 0 {
44						t.Fatal("zero highlight")
45					}
46				}
47				if c.Op == "caret" {
48					caret++
49					if c.Rect.W != 1 {
50						t.Fatalf("caret width: %+v", c.Rect)
51					}
52				}
53			}
54			if count == 0 || caret != 1 || !(maxX > minX) {
55				t.Fatalf("selection=%d caret=%d extent=%g:%g", count, caret, minX, maxX)
56			}
57			if tc.name == "arabic" {
58				var x float64
59				for _, c := range r.output.Display {
60					if c.Op == "caret" {
61						x = c.Rect.X
62					}
63				}
64				if math.Abs(x-minX) > 2 {
65					t.Fatalf("RTL trailing caret at %g, highlight starts %g", x, minX)
66				}
67			}
68		})
69	}
70}

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