-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvim.js
More file actions
137 lines (117 loc) · 3.66 KB
/
vim.js
File metadata and controls
137 lines (117 loc) · 3.66 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
Vim = {};
Vim.port = chrome.extension.connect({name: "tabs"});
Vim.scroll_amount = 50;
Vim.key_buffer = "";
Vim.multiBinds = {};
//always defined
function scrollDown() {
window.scrollBy(0,Vim.scroll_amount);
}
function scrollUp() {
window.scrollBy(0,-Vim.scroll_amount);
}
function scrollLeft() {
window.scrollBy(-Vim.scroll_amount,0);
}
function scrollRight() {
window.scrollBy(Vim.scroll_amount,0);
}
function topOfPage() {
window.scroll(0,0);
}
function bottomOfPage() {
console.log("bottom");
window.scroll(0,999999999);
}
function inputKey(inKey, keyFunc) {
$(document).bind('keydown', {combi:inKey, disableInInput: true}, function () {
keyFunc();
reset;
});
}
function specialKey(inKey, keyFunc) {
$(document).bind('keydown', {combi:inKey, disableInInput: false}, function () {
keyFunc();
reset();
});
}
function unKey(inkey) {
$(document).unbind('keydown', inKey);
}
var multiKeyFunc = null;
var multiKeysArr = null;
function multiBind(inKeys, keyFunc) {
if (inKeys.indexOf(" ") != -1) {
inKeysArr = inKeys.split(' ');
inKey = inKeysArr.shift();
Vim.multiBinds.push(inKey);
multiKeyFunc = keyFunc;
multiKeysArr = inKeysArr;
inputKey(inKey, function () {
Vim.key_buffer = inKey;
unKey(inKey);
setTimeout(function (Vim) {
multiBind(inKeysArr.join(" "), multiKeyFunc)}, 100);
});
} else {
inputKey(inKeys, function () {
keyFunc();
unKey(inKeys);
setTimeout(bindDefaults, 100);
});
}
}
function deleteTab() {
Vim.port.postMessage({method:"delete"});
}
function refresh() {
location.reload(true);
}
function nextTab() {
Vim.port.postMessage({method:"next"});
return false;
}
function prevTab() {
Vim.port.postMessage({method:"previous"});
return false;
}
// big and hairy like a whale
function createCmdLine() {
//do something good
}
// changes all key commands, binds all kinds of stuff
function find() {
//do something good
}
function reset() {
$(":input").blur();
unBindMultikeys();
bindDefaults();
}
function add_number(elem, num) {
console.log(elem);
var elem_top = elem.offsetTop;
var elem_left = elem.offsetLeft;
console.log(elem_top);
console.log(elem_left);
$(elem).after('<div class="vim_nums" style="position:absolute;left:' + elem_left + 'px;top:' + elem_top + 'px" "id="' + num + '" url="' + elem.href + '">' + num + '</div>')
}
//rebinds all the standard commands
function bindDefaults() {
console.log("Binding Defaults");
inputKey('j', scrollDown);
inputKey('k', scrollUp);
inputKey('h', scrollLeft);
inputKey('l', scrollRight);
specialKey('ctrl+o', function () {history.go(-1);return false;});
specialKey('ctrl+i', function () {history.go(1);return false;});
inputKey('r', refresh);
specialKey('ctrl+p', prevTab);
specialKey('ctrl+n', nextTab);
inputKey('d', deleteTab);
specialKey('esc', reset);
inputKey('f', find);
inputKey('shift+g', bottomOfPage);
multiBind('g g', topOfPage);
}
bindDefaults();