v0.33.2 57f21d6

keychord_test.go RawHistoryFolder

1package keychord
2
3import (
4	"testing"
5
6	"github.com/stretchr/testify/assert"
7	"github.com/stretchr/testify/require"
8)
9
10func TestCanonicalize_SameBindingSameString(t *testing.T) {
11	groups := [][]string{
12		{"right", "arrowright", "Right", "ArrowRight"},
13		{"left", "arrowleft"},
14		{"escape", "esc", "Escape"},
15		{"enter", "return", "Return"},
16		{"delete", "del"},
17		{"pageup", "page_up"},
18		{"ctrl+t", "control+t", "CTRL+t", " Ctrl + t"},
19		{"ctrl+shift+t", "Ctrl+Shift+T", "shift+ctrl+t", "control+shift+T", "Control+T"},
20		{"M", "shift+m", "shift+M"},
21		{"ctrl+plus", "ctrl++", "ctrl+Plus"},
22		{"plus", "+"},
23		{"minus", "-"},
24		{"alt+[", "alt+bracketleft"},
25		{"alt+shift+tab", "shift+alt+tab"},
26		{" ctrl + t ", "ctrl+t"},
27	}
28	for _, group := range groups {
29		want, ok := Canonicalize(group[0])
30		require.True(t, ok, group[0])
31		for _, spelling := range group[1:] {
32			got, ok := Canonicalize(spelling)
33			require.True(t, ok, spelling)
34			assert.Equal(t, want, got, "%q should equal %q", spelling, group[0])
35		}
36	}
37}
38
39func TestCanonicalize_DifferentBindingsDiffer(t *testing.T) {
40	pairs := [][2]string{
41		{"m", "M"},
42		{"ctrl+t", "alt+t"},
43		{"ctrl+t", "t"},
44		{"left", "right"},
45		{"ctrl+shift+t", "ctrl+t"},
46		{"1", "f1"},
47	}
48	for _, pair := range pairs {
49		a, ok := Canonicalize(pair[0])
50		require.True(t, ok, pair[0])
51		b, ok := Canonicalize(pair[1])
52		require.True(t, ok, pair[1])
53		assert.NotEqual(t, a, b, "%q vs %q", pair[0], pair[1])
54	}
55}
56
57func TestCanonicalize_CanonicalForm(t *testing.T) {
58	tests := map[string]string{
59		"arrowright":          "right",
60		"Control+Shift+T":     "ctrl+shift+t",
61		"shift+alt+ctrl+Esc":  "ctrl+alt+shift+escape",
62		"M":                   "shift+m",
63		"ctrl++":              "ctrl+plus",
64		"%":                   "%",
65		"shift+%":             "shift+%",
66		"f5":                  "f5",
67		"0":                   "0",
68		"alt+bracketleft":     "alt+bracketleft",
69		"ctrl+arrowleft":      "ctrl+left",
70		"  Alt + Page_Down  ": "alt+pagedown",
71	}
72	for in, want := range tests {
73		got, ok := Canonicalize(in)
74		require.True(t, ok, in)
75		assert.Equal(t, want, got, in)
76	}
77}
78
79func TestParse_Invalid(t *testing.T) {
80	for _, in := range []string{"", "   ", "ctrl+", "ctrl", "unknownkey", "ctrl+unknownkey", "a+b", "é"} {
81		_, ok := Parse(in)
82		assert.False(t, ok, "%q", in)
83	}
84}
85
86func TestKeyNames_AreCanonicalAndStable(t *testing.T) {
87	names := KeyNames()
88	require.Contains(t, names, "left")
89	require.Contains(t, names, "plus")
90	require.NotContains(t, names, "arrowleft")
91	for _, name := range names {
92		got, ok := canonicalKey(name)
93		require.True(t, ok, name)
94		assert.Equal(t, name, got)
95	}
96}

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 8

Tags 42

↑↓ moveenter openesc close