v0.0.77 cb8526c

paste_collapse_test.go RawHistoryFolder

1package tui
2
3import (
4	"strings"
5	"testing"
6)
7
8// TestPasteCollapseInsertsPlaceholder verifies that a multi-line
9// paste gets collapsed to the "[paste #N +L lines]" placeholder
10// in the editor buffer, leaving the full body behind the scenes.
11func TestPasteCollapseInsertsPlaceholder(t *testing.T) {
12	e := NewEditor("▌ ")
13	body := "line1\nline2\nline3\nline4"
14	e.HandleKey(Key{Kind: KeyPaste, Paste: body})
15
16	got := e.Value()
17	want := "[pasted text #1 +4 lines]"
18	if got != want {
19		t.Fatalf("editor Value: want %q, got %q", want, got)
20	}
21	if e.SubmitValue() != body {
22		t.Fatalf("SubmitValue didn't expand placeholder: got %q", e.SubmitValue())
23	}
24}
25
26// TestPasteCollapseSingleLineFallthrough ensures short pastes are
27// NOT collapsed — single-line drag-drop file paths and short
28// two-line snippets should appear inline so the user can edit
29// them in place.
30func TestPasteCollapseSingleLineFallthrough(t *testing.T) {
31	e := NewEditor("▌ ")
32	e.HandleKey(Key{Kind: KeyPaste, Paste: "hello world"})
33	if strings.Contains(e.Value(), "[pasted text #") {
34		t.Errorf("single-line paste should not collapse, got %q", e.Value())
35	}
36
37	e2 := NewEditor("▌ ")
38	e2.HandleKey(Key{Kind: KeyPaste, Paste: "line1\nline2"})
39	if strings.Contains(e2.Value(), "[pasted text #") {
40		t.Errorf("two-line paste should not collapse, got %q", e2.Value())
41	}
42}
43
44// TestPasteCollapseSequentialIDs makes sure two separate pastes get
45// distinct ids and both expand correctly in SubmitValue.
46func TestPasteCollapseSequentialIDs(t *testing.T) {
47	e := NewEditor("▌ ")
48	a := "aaa\nbbb\nccc"
49	b := "xxx\nyyy\nzzz"
50	e.HandleKey(Key{Kind: KeyPaste, Paste: a})
51	e.Insert(" ")
52	e.HandleKey(Key{Kind: KeyPaste, Paste: b})
53
54	visible := e.Value()
55	if !strings.Contains(visible, "[pasted text #1 +3 lines]") ||
56		!strings.Contains(visible, "[pasted text #2 +3 lines]") {
57		t.Fatalf("expected two placeholders in %q", visible)
58	}
59
60	full := e.SubmitValue()
61	if !strings.Contains(full, a) || !strings.Contains(full, b) {
62		t.Fatalf("SubmitValue missing bodies: %q", full)
63	}
64}
65
66// TestPasteCollapseClearResetsMap verifies that Clear drops the
67// stored pastes so stale ids can't leak into a follow-up turn
68// (same placeholder number could otherwise be reused to expand to
69// the wrong body).
70func TestPasteCollapseClearResetsMap(t *testing.T) {
71	e := NewEditor("▌ ")
72	e.HandleKey(Key{Kind: KeyPaste, Paste: "a\nb\nc"})
73	e.Clear()
74
75	// A fresh paste must start at id #1 again.
76	e.HandleKey(Key{Kind: KeyPaste, Paste: "d\ne\nf"})
77	if !strings.Contains(e.Value(), "[pasted text #1 ") {
78		t.Errorf("Clear didn't reset pasteSeq: %q", e.Value())
79	}
80}

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 477

↑↓ moveenter openesc close