v0.1.0 47aaa0f

empty_caret_test.go RawHistoryFolder

1package ui
2
3import (
4	"fmt"
5	"testing"
6
7	"github.com/bnema/nefergui/internal/css"
8	"github.com/bnema/nefergui/internal/text"
9)
10
11func TestEmptyLabelsDoNotReserveEditorLine(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.Build(func(f *Frame) {
19		root := f.Root()
20		root.Text("")
21		root.Heading("")
22	})
23	if len(r.output.Tree.Children) != 2 {
24		t.Fatalf("empty labels: got %d children, want 2", len(r.output.Tree.Children))
25	}
26	for _, child := range r.output.Tree.Children {
27		if child.Content.H != 0 || len(child.Lines) != 0 {
28			t.Fatalf("empty label reserves line: %+v", child)
29		}
30	}
31}
32
33func TestEmptyTextareaCaretUsesLineHeight(t *testing.T) {
34	catalog, err := text.Load(text.DirectorySource("../../testdata/fonts"))
35	if err != nil {
36		t.Fatal(err)
37	}
38	for _, height := range []string{"normal", "1.5", "30px", "1.5em", "150%"} {
39		t.Run(height, func(t *testing.T) {
40			r := newRuntime()
41			r.setTextEngine(text.NewEngine(catalog))
42			r.styles = css.Compile(css.UA(), css.Parse(fmt.Sprintf(`textarea {height:400px;width:300px;font-size:20px;line-height:%s}`, height)))
43			value := ""
44			view := func(f *Frame) { f.Root().Textarea("Document", &value) }
45			r.Build(view)
46			r.route(key("Tab"))
47			r.Build(view)
48			caretHeight := func() float64 {
49				for _, cmd := range r.output.Display {
50					if cmd.Op == "caret" {
51						return cmd.Rect.H
52					}
53				}
54				t.Fatal("missing caret")
55				return 0
56			}
57			empty := caretHeight()
58			if empty <= 0 || empty >= 100 {
59				t.Fatalf("empty caret height=%g", empty)
60			}
61			value = "x"
62			r.Redraw()
63			r.Build(view)
64			if got := caretHeight(); got != empty {
65				t.Fatalf("empty=%g populated=%g", empty, got)
66			}
67		})
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