-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathconfig.js
118 lines (107 loc) · 2.75 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/** Homepage
* The page that's displayed by default when no URL is provided
**/
const homepage = 'https://github.com/chase/awrit';
/** Keybindings
*
* @typedef {import('./src/keybindings').KeyBindingAction} KeyBindingAction
*/
/**
* Keybindings configuration object that maps Neovim-style key sequences to actions.
*
* Keybinding Format:
* - Single key: "a", "b", "1", etc.
* - Special keys: "<Tab>", "<Enter>", etc.
* - Modifiers:
* - <C-...> for Ctrl (e.g., <C-s> for Ctrl+S)
* - <A-...> for Alt
* - <S-...> for Shift
* - <M-...> for Meta/Command
* - Multiple modifiers can be combined: <C-A-s> for Ctrl+Alt+S
* - Multi-key sequences: <C-w>l for Ctrl+W followed by L
*
* Behavior:
* - Single-key bindings execute immediately
* - Multi-key bindings match exact sequences
* - Modifier order is handled consistently (e.g., <C-A-s> matches both Ctrl+Alt+S and Alt+Ctrl+S)
* - When a key sequence is a prefix of another binding:
* - The system waits for a timeout period
* - If the longer sequence is completed within the timeout, it executes
* - If no further keys are pressed within the timeout, the shorter binding executes
*
* Example:
* ```js
* {
* // Executes after timeout if no longer sequence
* '<C-a>': () => console.log('Select all'),
* // Executes after timeout if no longer sequence
* '<C-w>': () => console.log('Close window'),
* // Executes immediately if pressed within timeout
* '<C-w>l': () => console.log('Next window'),
* }
* ```
*
* @type {Record<string, KeyBindingAction> & {
* mac?: Record<string, KeyBindingAction>,
* linux?: Record<string, KeyBindingAction>
* }}
*/
const keybindings = {
'<C-c>': () => {
process.emit('SIGINT');
},
'<Mouse4>': back,
'<Mouse5>': forward,
mac: {
'<M-a>': ({ view }) => {
view.focusedContent.selectAll();
},
'<M-]>': forward,
'<M-[>': back,
'<M-f>': find,
'<M-r>': refresh,
},
linux: {
'<C-]>': forward,
'<C-[>': back,
'<C-f>': find,
'<C-r>': refresh,
},
};
/** @type {KeyBindingAction} */
function back({ view }) {
view.back();
}
/** @type {KeyBindingAction} */
function forward({ view }) {
view.forward();
}
/** @type {KeyBindingAction} */
function refresh({ view }) {
view.refresh();
}
function find({ view }) {
view.toolbar.webContents.send('toolbar:toggle-find');
view.content.blurWebView();
view.toolbar.focusOnWebView();
view.focusedContent = view.toolbar.webContents;
}
const config = {
homepage,
keybindings,
};
module.exports = config;
/** Utilities */
const util = require('node:util');
function debug(...args) {
process.stderr.write(
util
.formatWithOptions(
{
colors: true,
},
...args,
)
.replaceAll('\n', '\r\n'),
);
}