v0.30.0 eb3068f

transform_legacy_test.go RawHistoryFolder

1package config
2
3import (
4	"testing"
5
6	"github.com/stretchr/testify/assert"
7	"github.com/stretchr/testify/require"
8)
9
10func TestTransformLegacyActions_SliceFormat(t *testing.T) {
11	transformer := NewLegacyConfigTransformer()
12
13	rawConfig := map[string]any{
14		"workspace": map[string]any{
15			"pane_mode": map[string]any{
16				"actions": map[string]any{
17					"focus-left": []any{"h", "arrowleft"},
18				},
19			},
20		},
21	}
22
23	transformer.TransformLegacyActions(rawConfig)
24
25	actions := rawConfig["workspace"].(map[string]any)["pane_mode"].(map[string]any)["actions"].(map[string]any)
26	binding, ok := actions["focus-left"].(map[string]any)
27	require.True(t, ok, "should be converted to map")
28
29	keys, ok := binding["keys"].([]string)
30	require.True(t, ok, "keys should be []string")
31	assert.Equal(t, []string{"h", "arrowleft"}, keys)
32	assert.NotEmpty(t, binding["desc"], "should have description from defaults")
33}
34
35func TestTransformLegacyActions_AllModes(t *testing.T) {
36	transformer := NewLegacyConfigTransformer()
37
38	rawConfig := map[string]any{
39		"workspace": map[string]any{
40			"pane_mode": map[string]any{
41				"actions": map[string]any{
42					"focus-left": []any{"h"},
43				},
44			},
45			"tab_mode": map[string]any{
46				"actions": map[string]any{
47					"next-tab": []any{"l"},
48				},
49			},
50			"resize_mode": map[string]any{
51				"actions": map[string]any{
52					"resize-increase": []any{"+"},
53				},
54			},
55			"shortcuts": map[string]any{
56				"actions": map[string]any{
57					"close_pane": []any{"ctrl+w"},
58				},
59			},
60		},
61		"session": map[string]any{
62			"session_mode": map[string]any{
63				"actions": map[string]any{
64					"session-manager": []any{"m"},
65				},
66			},
67		},
68	}
69
70	transformer.TransformLegacyActions(rawConfig)
71
72	// Check pane mode
73	paneActions := rawConfig["workspace"].(map[string]any)["pane_mode"].(map[string]any)["actions"].(map[string]any)
74	paneFocus, ok := paneActions["focus-left"].(map[string]any)
75	require.True(t, ok)
76	assert.Equal(t, []string{"h"}, paneFocus["keys"])
77
78	// Check tab mode
79	tabActions := rawConfig["workspace"].(map[string]any)["tab_mode"].(map[string]any)["actions"].(map[string]any)
80	tabNext, ok := tabActions["next-tab"].(map[string]any)
81	require.True(t, ok)
82	assert.Equal(t, []string{"l"}, tabNext["keys"])
83
84	// Check resize mode
85	resizeActions := rawConfig["workspace"].(map[string]any)["resize_mode"].(map[string]any)["actions"].(map[string]any)
86	resizeInc, ok := resizeActions["resize-increase"].(map[string]any)
87	require.True(t, ok)
88	assert.Equal(t, []string{"+"}, resizeInc["keys"])
89
90	// Check shortcuts
91	shortcutActions := rawConfig["workspace"].(map[string]any)["shortcuts"].(map[string]any)["actions"].(map[string]any)
92	closePane, ok := shortcutActions["close_pane"].(map[string]any)
93	require.True(t, ok)
94	assert.Equal(t, []string{"ctrl+w"}, closePane["keys"])
95
96	// Check session mode
97	sessionActions := rawConfig["session"].(map[string]any)["session_mode"].(map[string]any)["actions"].(map[string]any)
98	sessionMgr, ok := sessionActions["session-manager"].(map[string]any)
99	require.True(t, ok)
100	assert.Equal(t, []string{"m"}, sessionMgr["keys"])
101}
102
103func TestTransformLegacyActions_AlreadyNewFormat(t *testing.T) {
104	transformer := NewLegacyConfigTransformer()
105
106	rawConfig := map[string]any{
107		"workspace": map[string]any{
108			"pane_mode": map[string]any{
109				"actions": map[string]any{
110					"focus-left": map[string]any{
111						"keys": []string{"h"},
112						"desc": "Custom description",
113					},
114				},
115			},
116		},
117	}
118
119	transformer.TransformLegacyActions(rawConfig)
120
121	actions := rawConfig["workspace"].(map[string]any)["pane_mode"].(map[string]any)["actions"].(map[string]any)
122	binding := actions["focus-left"].(map[string]any)
123
124	// Should remain unchanged
125	assert.Equal(t, "Custom description", binding["desc"])
126}
127
128func TestTransformLegacyActions_MissingSection(t *testing.T) {
129	transformer := NewLegacyConfigTransformer()
130
131	rawConfig := map[string]any{
132		"appearance": map[string]any{
133			"theme": "dark",
134		},
135	}
136
137	// Should not panic
138	transformer.TransformLegacyActions(rawConfig)
139
140	// Config should be unchanged
141	assert.Equal(t, "dark", rawConfig["appearance"].(map[string]any)["theme"])
142}
143
144func TestTransformLegacyActions_EmptyConfig(t *testing.T) {
145	transformer := NewLegacyConfigTransformer()
146
147	rawConfig := map[string]any{}
148
149	// Should not panic
150	transformer.TransformLegacyActions(rawConfig)
151
152	assert.Empty(t, rawConfig)
153}
154
155func TestTransformLegacyActions_PartialPath(t *testing.T) {
156	transformer := NewLegacyConfigTransformer()
157
158	rawConfig := map[string]any{
159		"workspace": map[string]any{
160			"pane_mode": map[string]any{
161				// actions section missing
162			},
163		},
164	}
165
166	// Should not panic
167	transformer.TransformLegacyActions(rawConfig)
168
169	// Verify config is unchanged
170	require.NotNil(t, rawConfig["workspace"])
171}
172
173func TestTransformLegacyEngineConfig_RemovesDeprecatedContextMenuHandler(t *testing.T) {
174	transformer := NewLegacyConfigTransformer()
175
176	rawConfig := map[string]any{
177		"engine": map[string]any{
178			"cef": map[string]any{
179				"enable_context_menu_handler": true,
180			},
181		},
182	}
183
184	transformer.TransformLegacyEngineConfig(rawConfig)
185
186	cef := rawConfig["engine"].(map[string]any)["cef"].(map[string]any)
187	_, exists := cef["enable_context_menu_handler"]
188	assert.False(t, exists)
189}
190
191func TestTransformLegacyEngineConfig_MigratesLegacyCEFWindowlessFrameRateDefault(t *testing.T) {
192	transformer := NewLegacyConfigTransformer()
193	rawConfig := map[string]any{
194		"engine": map[string]any{
195			"cef": map[string]any{
196				"windowless_frame_rate": 60,
197			},
198		},
199	}
200
201	transformer.TransformLegacyEngineConfig(rawConfig)
202
203	cef := rawConfig["engine"].(map[string]any)["cef"].(map[string]any)
204	assert.Equal(t, true, cef["adaptive_windowless_frame_rate"])
205	assert.Equal(t, 0, cef["windowless_frame_rate"])
206	assert.Equal(t, defaultCEFWindowlessFrameRateMax, cef["windowless_frame_rate_max"])
207}
208
209func TestTransformLegacyEngineConfig_UpgradesObsoletePreciseScrollDefault(t *testing.T) {
210	transformer := NewLegacyConfigTransformer()
211	rawConfig := map[string]any{
212		"engine": map[string]any{
213			"cef": map[string]any{
214				"input": map[string]any{
215					"scroll_precise_multiplier": 0.35,
216				},
217			},
218		},
219	}
220
221	transformer.TransformLegacyEngineConfig(rawConfig)
222
223	input := rawConfig["engine"].(map[string]any)["cef"].(map[string]any)["input"].(map[string]any)
224	assert.InDelta(t, defaultCEFScrollPreciseMultiplier, input["scroll_precise_multiplier"], 0.001)
225}
226
227func TestTransformLegacyEngineConfig_MigratesLegacyTouchpadScrollKey(t *testing.T) {
228	transformer := NewLegacyConfigTransformer()
229	rawConfig := map[string]any{
230		"engine": map[string]any{
231			"cef": map[string]any{
232				"input": map[string]any{
233					"scroll_touchpad_multiplier": 0.35,
234				},
235			},
236		},
237	}
238
239	transformer.TransformLegacyEngineConfig(rawConfig)
240
241	input := rawConfig["engine"].(map[string]any)["cef"].(map[string]any)["input"].(map[string]any)
242	assert.InDelta(t, defaultCEFScrollPreciseMultiplier, input["scroll_precise_multiplier"], 0.001)
243	assert.NotContains(t, input, "scroll_touchpad_multiplier")
244}
245
246func TestTransformLegacyEngineConfig_PreservesCustomPreciseScrollMultiplier(t *testing.T) {
247	transformer := NewLegacyConfigTransformer()
248	rawConfig := map[string]any{
249		"engine": map[string]any{
250			"cef": map[string]any{
251				"input": map[string]any{
252					"scroll_precise_multiplier": 4.0,
253				},
254			},
255		},
256	}
257
258	transformer.TransformLegacyEngineConfig(rawConfig)
259
260	input := rawConfig["engine"].(map[string]any)["cef"].(map[string]any)["input"].(map[string]any)
261	assert.InDelta(t, 4.0, input["scroll_precise_multiplier"], 0.001)
262}
263
264func TestTransformLegacyEngineConfig_PreservesCustomLegacyTouchpadScrollMultiplier(t *testing.T) {
265	transformer := NewLegacyConfigTransformer()
266	rawConfig := map[string]any{
267		"engine": map[string]any{
268			"cef": map[string]any{
269				"input": map[string]any{
270					"scroll_touchpad_multiplier": 4.0,
271				},
272			},
273		},
274	}
275
276	transformer.TransformLegacyEngineConfig(rawConfig)
277
278	input := rawConfig["engine"].(map[string]any)["cef"].(map[string]any)["input"].(map[string]any)
279	assert.InDelta(t, 4.0, input["scroll_precise_multiplier"], 0.001)
280	assert.NotContains(t, input, "scroll_touchpad_multiplier")
281}
282
283func TestTransformLegacyEngineConfig_PrefersCustomLegacyTouchpadOverGeneratedPreciseDefault(t *testing.T) {
284	transformer := NewLegacyConfigTransformer()
285	rawConfig := map[string]any{
286		"engine": map[string]any{
287			"cef": map[string]any{
288				"input": map[string]any{
289					"scroll_touchpad_multiplier": 4.0,
290					"scroll_precise_multiplier":  0.35,
291				},
292			},
293		},
294	}
295
296	transformer.TransformLegacyEngineConfig(rawConfig)
297
298	input := rawConfig["engine"].(map[string]any)["cef"].(map[string]any)["input"].(map[string]any)
299	assert.InDelta(t, 4.0, input["scroll_precise_multiplier"], 0.001)
300	assert.NotContains(t, input, "scroll_touchpad_multiplier")
301}
302
303func TestTransformLegacyEngineConfig_PreservesExplicitCEFWindowlessFrameRate(t *testing.T) {
304	transformer := NewLegacyConfigTransformer()
305	rawConfig := map[string]any{
306		"engine": map[string]any{
307			"cef": map[string]any{
308				"adaptive_windowless_frame_rate": false,
309				"windowless_frame_rate":          60,
310			},
311		},
312	}
313
314	transformer.TransformLegacyEngineConfig(rawConfig)
315
316	cef := rawConfig["engine"].(map[string]any)["cef"].(map[string]any)
317	assert.Equal(t, false, cef["adaptive_windowless_frame_rate"])
318	assert.Equal(t, 60, cef["windowless_frame_rate"])
319	_, hasMax := cef["windowless_frame_rate_max"]
320	assert.False(t, hasMax)
321}
322
323func TestTransformLegacyEngineConfig_PreservesNonDefaultCEFWindowlessFrameRate(t *testing.T) {
324	transformer := NewLegacyConfigTransformer()
325	rawConfig := map[string]any{
326		"engine": map[string]any{
327			"cef": map[string]any{
328				"windowless_frame_rate": 144,
329			},
330		},
331	}
332
333	transformer.TransformLegacyEngineConfig(rawConfig)
334
335	cef := rawConfig["engine"].(map[string]any)["cef"].(map[string]any)
336	_, hasAdaptive := cef["adaptive_windowless_frame_rate"]
337	assert.False(t, hasAdaptive)
338	assert.Equal(t, 144, cef["windowless_frame_rate"])
339}
340
341func TestTransformLegacyEngineConfig_MissingCefSection(t *testing.T) {
342	transformer := NewLegacyConfigTransformer()
343	rawConfig := map[string]any{
344		"engine": map[string]any{
345			"webkit": map[string]any{"enabled": true},
346		},
347	}
348
349	transformer.TransformLegacyEngineConfig(rawConfig)
350
351	engine, ok := rawConfig["engine"].(map[string]any)
352	require.True(t, ok)
353	assert.NotNil(t, engine)
354	assert.Equal(t, true, engine["webkit"].(map[string]any)["enabled"])
355}
356
357func TestTransformLegacyEngineConfig_MissingContextMenuHandlerKey(t *testing.T) {
358	transformer := NewLegacyConfigTransformer()
359	rawConfig := map[string]any{
360		"engine": map[string]any{
361			"cef": map[string]any{
362				"other_setting": true,
363			},
364		},
365	}
366
367	transformer.TransformLegacyEngineConfig(rawConfig)
368
369	cef := rawConfig["engine"].(map[string]any)["cef"].(map[string]any)
370	assert.True(t, cef["other_setting"].(bool))
371	_, exists := cef["enable_context_menu_handler"]
372	assert.False(t, exists)
373}
374
375func TestTransformLegacyEngineConfig_NonMapEngineSection(t *testing.T) {
376	transformer := NewLegacyConfigTransformer()
377	rawConfig := map[string]any{
378		"engine": "invalid",
379	}
380
381	transformer.TransformLegacyEngineConfig(rawConfig)
382
383	assert.Equal(t, "invalid", rawConfig["engine"])
384}
385
386func TestTransformLegacyActions_UnknownAction(t *testing.T) {
387	transformer := NewLegacyConfigTransformer()
388
389	rawConfig := map[string]any{
390		"workspace": map[string]any{
391			"pane_mode": map[string]any{
392				"actions": map[string]any{
393					"unknown-action": []any{"x"},
394				},
395			},
396		},
397	}
398
399	transformer.TransformLegacyActions(rawConfig)
400
401	actions := rawConfig["workspace"].(map[string]any)["pane_mode"].(map[string]any)["actions"].(map[string]any)
402	binding, ok := actions["unknown-action"].(map[string]any)
403	require.True(t, ok)
404	assert.Equal(t, []string{"x"}, binding["keys"])
405	assert.Empty(t, binding["desc"], "unknown action should have empty description")
406}

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