forked from mutle/vim.safariextension
-
Notifications
You must be signed in to change notification settings - Fork 1
/
vim-keybindings.js
65 lines (58 loc) · 1.24 KB
/
vim-keybindings.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
var keycombo = '';
window.document.addEventListener("keydown", function(e) {
var t = {}, c = String.fromCharCode(e.keyCode).toLowerCase(), SCROLL_STEP = 35;
if(window.document.activeElement !== window.document.body) {
if (e.keyCode == 27) {
window.document.activeElement.blur();
}
return;
}
t.scroll = function(x, y) {
window.scrollBy(x, y);
};
t.scrollTo = function(x, y) {
window.scrollTo(x, y);
};
t.halfWindowHeight = function() {
return window.innerHeight / 2;
};
t.screenHeight = function() {
return document.body.offsetHeight;
};
if(e.shiftKey) c = c.toUpperCase();
switch(c) {
case 'g':
if(keycombo == 'g')
t.scrollTo(0, 0);
else {
keycombo = c;
window.setTimeout(function() { keycombo = ''; }, 500);
}
break;
case 'h':
t.scroll(-SCROLL_STEP, 0);
break;
case 'j':
t.scroll(0, SCROLL_STEP);
break;
case 'k':
t.scroll(0, -SCROLL_STEP);
break;
case 'l':
t.scroll(SCROLL_STEP, 0);
break;
case 'd':
if(e.ctrlKey) {
t.scroll(0, t.halfWindowHeight());
}
break;
case 'u':
if(e.ctrlKey) {
t.scroll(0, -t.halfWindowHeight());
}
break;
case 'G':
t.scrollTo(0, t.screenHeight());
break;
}
});