v0.3.74 0f485af

view_diff_wrap_test.go RawHistoryFolder

1package tui
2
3import (
4	"strings"
5	"testing"
6)
7
8func TestRenderDiffRowWrapsWithoutLosingContent(t *testing.T) {
9	const width = 30
10	code := `const message = "alpha beta gamma delta epsilon"`
11	v := View{Theme: Dark}
12
13	rows := v.renderDiffRow("+"+code, width, v.Theme.Tool, 7, '+', "sample.go")
14	if len(rows) < 2 {
15		t.Fatalf("long diff line did not wrap: %q", rows)
16	}
17
18	var rebuilt strings.Builder
19	for i, row := range rows {
20		plain := stripANSI(row)
21		if got := visibleWidth(row); got > width {
22			t.Errorf("row %d width = %d, want <= %d: %q", i, got, width, plain)
23		}
24		prefix := "         "
25		if i == 0 {
26			prefix = "    +  7 "
27		}
28		if !strings.HasPrefix(plain, prefix) {
29			t.Fatalf("row %d prefix = %q, want %q", i, plain, prefix)
30		}
31		rebuilt.WriteString(strings.TrimPrefix(plain, prefix))
32	}
33	if got := rebuilt.String(); got != code {
34		t.Fatalf("wrapped content changed:\n got: %q\nwant: %q", got, code)
35	}
36	if strings.Contains(stripANSI(strings.Join(rows, "\n")), "...") {
37		t.Fatalf("wrapped diff still contains truncation ellipsis: %q", rows)
38	}
39}
40
41func TestRenderDiffRowWrapsUnicodeByDisplayWidth(t *testing.T) {
42	const width = 18
43	code := "名前 = 🙂🙂🙂 café résumé"
44	v := View{Theme: Dark}
45
46	rows := v.renderDiffRow("-"+code, width, v.Theme.Error, 12, '-', "")
47	if len(rows) < 2 {
48		t.Fatalf("long Unicode diff line did not wrap: %q", rows)
49	}
50
51	var rebuilt strings.Builder
52	for i, row := range rows {
53		plain := stripANSI(row)
54		if got := visibleWidth(row); got > width {
55			t.Errorf("row %d width = %d, want <= %d: %q", i, got, width, plain)
56		}
57		prefix := "         "
58		if i == 0 {
59			prefix = "    - 12 "
60		}
61		if !strings.HasPrefix(plain, prefix) {
62			t.Fatalf("row %d prefix = %q, want %q", i, plain, prefix)
63		}
64		rebuilt.WriteString(strings.TrimPrefix(plain, prefix))
65	}
66	if got := rebuilt.String(); got != code {
67		t.Fatalf("wrapped Unicode content changed:\n got: %q\nwant: %q", got, code)
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 476

↑↓ moveenter openesc close