forked from philc/vimium
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommands.js
160 lines (128 loc) · 5.51 KB
/
commands.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
var availableCommands = {};
var keyToCommandRegistry = {};
function addCommand(command, description, isBackgroundCommand) {
if (availableCommands[command])
{
console.log(command, "is already defined! Check commands.js for duplicates.");
return;
}
availableCommands[command] = { description: description, isBackgroundCommand: isBackgroundCommand };
}
function mapKeyToCommand(key, command) {
if (!availableCommands[command])
{
console.log(command, "doesn't exist!");
return;
}
keyToCommandRegistry[key] = { command: command, isBackgroundCommand: availableCommands[command].isBackgroundCommand };
}
function unmapKey(key) { delete keyToCommandRegistry[key]; }
function parseCustomKeyMappings(customKeyMappings) {
lines = customKeyMappings.split("\n");
for (var i = 0; i < lines.length; i++) {
if (lines[i][0] == "\"" || lines[i][0] == "#") { continue }
split_line = lines[i].split(" "); // TODO(ilya): Support all whitespace.
var lineCommand = split_line[0];
if (lineCommand == "map") {
if (split_line.length != 3) { continue; }
var key = split_line[1];
var vimiumCommand = split_line[2];
if (!availableCommands[vimiumCommand]) { continue }
console.log("Mapping", key, "to", vimiumCommand);
mapKeyToCommand(key, vimiumCommand);
}
else if (lineCommand == "unmap") {
if (split_line.length != 2) { continue; }
var key = split_line[1];
console.log("Unmapping", key);
unmapKey(key);
}
else if (lineCommand == "unmapAll") {
keyToCommandRegistry = {};
}
}
}
function clearKeyMappingsAndSetDefaults() {
keyToCommandRegistry = {};
mapKeyToCommand('?', 'showHelp');
mapKeyToCommand('j', 'scrollDown');
mapKeyToCommand('k', 'scrollUp');
mapKeyToCommand('h', 'scrollLeft');
mapKeyToCommand('l', 'scrollRight');
mapKeyToCommand('gg', 'scrollToTop');
mapKeyToCommand('G', 'scrollToBottom');
mapKeyToCommand('<c-e>', 'scrollDown');
mapKeyToCommand('<c-y>', 'scrollUp');
mapKeyToCommand('<c-d>', 'scrollPageDown');
mapKeyToCommand('<c-u>', 'scrollPageUp');
mapKeyToCommand('<c-f>', 'scrollFullPageDown');
mapKeyToCommand('<c-b>', 'scrollFullPageUp');
mapKeyToCommand('r', 'reload');
mapKeyToCommand('gf', 'toggleViewSource');
mapKeyToCommand('i', 'enterInsertMode');
mapKeyToCommand('H', 'goBack');
mapKeyToCommand('L', 'goForward');
mapKeyToCommand('zi', 'zoomIn');
mapKeyToCommand('zo', 'zoomOut');
mapKeyToCommand('f', 'activateLinkHintsMode');
mapKeyToCommand('F', 'activateLinkHintsModeToOpenInNewTab');
mapKeyToCommand('/', 'enterFindMode');
mapKeyToCommand('n', 'performFind');
mapKeyToCommand('N', 'performBackwardsFind');
mapKeyToCommand('yy', 'copyCurrentUrl');
mapKeyToCommand('K', 'nextTab');
mapKeyToCommand('J', 'previousTab');
mapKeyToCommand('gt', 'nextTab');
mapKeyToCommand('gT', 'previousTab');
mapKeyToCommand('t', 'createTab');
mapKeyToCommand('d', 'removeTab');
mapKeyToCommand('u', 'restoreTab');
}
// Navigating the current page:
addCommand('showHelp', 'Show help', true);
addCommand('scrollDown', 'Scroll down');
addCommand('scrollUp', 'Scroll up');
addCommand('scrollLeft', 'Scroll left');
addCommand('scrollRight', 'Scroll right');
addCommand('scrollToTop', 'Scroll to the top of the page');
addCommand('scrollToBottom', 'Scroll to the bottom of the page');
addCommand('scrollPageDown', 'Scroll a page down');
addCommand('scrollPageUp', 'Scroll a page up');
addCommand('scrollFullPageDown', 'Scroll a full page down');
addCommand('scrollFullPageUp', 'Scroll a full page up');
addCommand('reload', 'Reload the page');
addCommand('toggleViewSource', 'View page source');
addCommand('zoomIn', 'Zoom in');
addCommand('zoomOut', 'Zoom out');
addCommand('copyCurrentUrl', 'Copy the current URL to the clipboard');
addCommand('enterInsertMode', 'Enter insert mode');
addCommand('activateLinkHintsMode', 'Enter link hints mode to open links in current tab');
addCommand('activateLinkHintsModeToOpenInNewTab', 'Enter link hints mode to open links in new tab');
addCommand('enterFindMode', 'Enter find mode');
addCommand('performFind', 'Cycle forward to the next find match');
addCommand('performBackwardsFind', 'Cycle backward to the previous find match');
// Navigating your history:
addCommand('goBack', 'Go back in history');
addCommand('goForward', 'Go forward in history');
// Manipulating tabs:
addCommand('nextTab', 'Go one tab right', true);
addCommand('previousTab', 'Go one tab left', true);
addCommand('createTab', 'Create new tab', true);
addCommand('removeTab', 'Close current tab', true);
addCommand('restoreTab', "Restore closed tab", true);
// An ordered listing of all available commands, grouped by type. This is the order they will
// be shown in the help page.
var commandGroups = {
pageNavigation:
["scrollDown", "scrollUp", "scrollLeft", "scrollRight",
"scrollToTop", "scrollToBottom", "scrollPageDown", "scrollPageUp", "scrollFullPageDown",
"reload", "toggleViewSource", "zoomIn", "zoomOut", "copyCurrentUrl",
"enterInsertMode", "activateLinkHintsMode", "activateLinkHintsModeToOpenInNewTab",
"enterFindMode", "performFind", "performBackwardsFind"],
historyNavigation:
["goBack", "goForward"],
tabManipulation:
["nextTab", "previousTab", "createTab", "removeTab", "restoreTab"],
misc:
["showHelp"]
};