v0.10.0 0f4e9eb

script_cgo.go RawHistoryFolder

1//go:build webkit_cgo
2
3package webkit
4
5/*
6#cgo pkg-config: webkitgtk-6.0 gtk4
7#cgo CFLAGS: -I/usr/include/webkitgtk-6.0
8#include <stdlib.h>
9#include <webkit/webkit.h>
10
11static gboolean dumber_is_valid_web_view(WebKitWebView *wv) {
12    return WEBKIT_IS_WEB_VIEW(wv);
13}
14*/
15import "C"
16
17import "unsafe"
18
19func (w *WebView) canEvaluateJavaScript() bool {
20	if w == nil || w.destroyed || w.native == nil || w.native.wv == nil {
21		return false
22	}
23	if C.dumber_is_valid_web_view(w.native.wv) == C.gboolean(0) {
24		if w.native != nil {
25			w.native.wv = nil
26			w.native.view = nil
27		}
28		w.destroyed = true
29		return false
30	}
31	return true
32}
33
34func (w *WebView) InjectScript(js string) error {
35	if !w.canEvaluateJavaScript() {
36		return ErrNotImplemented
37	}
38	cjs := C.CString(js)
39	defer C.free(unsafe.Pointer(cjs))
40	// Fire-and-forget evaluation using the modern API
41	// length: -1 (NUL-terminated), world_name/source_uri: NULL, starting_line_number: 0
42	C.webkit_web_view_evaluate_javascript(
43		w.native.wv,
44		(*C.gchar)(cjs),
45		C.gssize(-1),
46		nil, // world_name
47		nil, // source_uri
48		nil, // cancellable
49		nil, // callback
50		nil, // user_data
51	)
52	return nil
53}
54
55// InjectScriptIntoWorld evaluates JavaScript in the specified script world.
56func (w *WebView) InjectScriptIntoWorld(js string, worldName string) error {
57	if !w.canEvaluateJavaScript() {
58		return ErrNotImplemented
59	}
60	cjs := C.CString(js)
61	defer C.free(unsafe.Pointer(cjs))
62
63	var cworld *C.gchar
64	if worldName != "" {
65		cworld = (*C.gchar)(C.CString(worldName))
66		defer C.free(unsafe.Pointer(cworld))
67	}
68
69	// Evaluate JavaScript in the specified world
70	C.webkit_web_view_evaluate_javascript(
71		w.native.wv,
72		(*C.gchar)(cjs),
73		C.gssize(-1),
74		cworld, // world_name
75		nil,    // source_uri
76		nil,    // cancellable
77		nil,    // callback
78		nil,    // user_data
79	)
80	return nil
81}

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