v0.33.2 57f21d6

input_focus_test.go RawHistoryFolder

1package cef
2
3import (
4	"testing"
5
6	cefmocks "github.com/bnema/purego-cef/cef/mocks"
7	"github.com/stretchr/testify/mock"
8	"github.com/stretchr/testify/require"
9)
10
11func TestWebViewFocusNextInputExecutesSafeFocusScript(t *testing.T) {
12	browser := cefmocks.NewMockBrowser(t)
13	frame := cefmocks.NewMockFrame(t)
14	browser.EXPECT().GetMainFrame().Return(frame).Once()
15	frame.EXPECT().ExecuteJavaScript(mock.MatchedBy(mockStringContaining(t,
16		`document.querySelectorAll("input,textarea,[contenteditable]")`,
17		`element.closest("[hidden],[inert],[aria-hidden=\"true\"]")`,
18		"getClientRects",
19		"HTMLInputElement",
20		"HTMLTextAreaElement",
21		"activeIndex",
22		"target.focus()",
23	)), "", int32(0)).Once()
24
25	(&WebView{browser: browser}).FocusNextInput()
26}
27
28func TestWebViewNavigatePageFocusExecutesDirectionalScript(t *testing.T) {
29	browser := cefmocks.NewMockBrowser(t)
30	frame := cefmocks.NewMockFrame(t)
31	browser.EXPECT().GetMainFrame().Return(frame).Once()
32	frame.EXPECT().ExecuteJavaScript(mock.MatchedBy(mockStringContaining(t,
33		"const direction = -1;",
34		"a[href]",
35		"textarea:not(:disabled)",
36		"document.activeElement",
37		"targetIndex",
38		"candidates[targetIndex].focus()",
39	)), "", int32(0)).Once()
40
41	(&WebView{browser: browser}).NavigatePageFocus(true)
42}
43
44func TestFocusNextInputScriptWrapsAndNoOpsWithoutEligibleTarget(t *testing.T) {
45	script := focusNextInputScript()
46
47	require.Contains(t, script, "const eligible = candidates.filter(isEligible);")
48	require.Contains(t, script, "if (eligible.length === 0) return;")
49	require.Contains(t, script, "const target = eligible[(activeIndex + 1 + eligible.length) % eligible.length];")
50	require.Contains(t, script, "!element.matches(\":disabled\") && !element.readOnly")
51	require.Contains(t, script, `hiddenInputTypes.has(element.type.toLowerCase())`)
52}
53
54func TestPageFocusNavigationScriptStopsAtPageBoundaries(t *testing.T) {
55	script := pageFocusNavigationScript(true)
56
57	require.Contains(t, script, "const direction = -1;")
58	require.Contains(t, script, "if (targetIndex < 0 || targetIndex >= candidates.length) return;")
59	require.Contains(t, script, "candidates[targetIndex].focus();")
60}

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