blob: 8cf0aed790b77b4e75433a4ac7ee1fca34cddf8a (
plain) (
blame)
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
|
import * as scrolls from './scrolls';
import FooterLine from './footer-line';
import * as actions from '../shared/actions';
var footer = null;
const invokeEvent = (action) => {
if (typeof action === 'undefined' || action === null) {
return;
}
switch (action[0]) {
case actions.CMD_OPEN:
footer = new FooterLine(document);
footer.input.value = ':';
footer.focus();
break;
case actions.SCROLL_UP:
scrolls.scrollUp(window, action[1] || 1);
break;
case actions.SCROLL_DOWN:
scrolls.scrollDown(window, action[1] || 1);
break;
case actions.SCROLL_TOP:
scrolls.scrollTop(window, action[1]);
break;
case actions.SCROLL_BOTTOM:
scrolls.scrollBottom(window, action[1]);
break;
}
}
const isModifier = (code) => {
return code === KeyboardEvent.DOM_VK_SHIFT ||
code === KeyboardEvent.DOM_VK_ALT ||
code === KeyboardEvent.DOM_VK_CONTROL ||
code === KeyboardEvent.DOM_VK_META;
}
window.addEventListener("keydown", (e) => {
if (e.target instanceof HTMLInputElement) {
return;
}
if (isModifier(e.keyCode)) {
return;
}
let request = {
type: 'event.keydown',
code: e.keyCode,
shift: e.shiftKey,
alt: e.altKey,
meta: e.metaKey,
ctrl: e.ctrlKey,
}
browser.runtime.sendMessage(request)
.then(invokeEvent,
(err) => {
console.log(`Vim Vixen: ${err}`);
});
});
|