Skip to content

Commit 0ff3fa2

Browse files
committed
merge
2 parents 2f8807d + 1930b5f commit 0ff3fa2

File tree

8 files changed

+450
-194
lines changed

8 files changed

+450
-194
lines changed

README.markdown

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ The Settings page can be found by clicking the Options button next to Vimium on
2020
Keyboard Bindings
2121
-----------------
2222

23-
<c-x> is to be interpreted as ctrl + x together.
23+
Modifier keys are specified as follows: <c-x>, <m-x>, <a-x> for ctrl+x, meta+x, and alt+x
24+
respectively.
2425

2526
Navigating the current page:
2627
h scroll left
@@ -46,8 +47,8 @@ Navigating the current page:
4647
y copy the current url to the clipboard
4748

4849
Navigating your history:
49-
ba, H go back in history
50-
fw, fo, L go forward in history
50+
H go back in history
51+
L go forward in history
5152

5253
Manipulating tabs:
5354
J, gT go one tab left
@@ -59,6 +60,8 @@ Manipulating tabs:
5960
Vimium supports command repetition so, for example, hitting '5t' will open 5 tabs in rapid succession. ESC (or
6061
<c-[>) will clear any partial commands in the queue.
6162

63+
Keys can be unmapped and remapped to different commands under Advanced Options.
64+
6265
Contributing
6366
------------
6467

@@ -69,10 +72,11 @@ include a change to the CREDITS file with your patch.
6972
Release Notes
7073
-------------
7174

72-
1.16 (Unreleased)
75+
1.16 (03/09/2010)
7376

7477
- Add support for configurable key mappings under Advanced Options.
75-
- Various bug fixes related to key stroke handling.
78+
- A help dialog which shows all currently bound keyboard shortcuts. Type "?" to see it.
79+
- Bug fixes related to key stroke handling.
7680

7781
1.15 (01/31/2010)
7882

background_page.html

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
<script type="text/javascript" charset="utf-8">
55
// Currently we need to remember to change this each time we push. Chromium #15242 will enable us
66
// to retrieve this programmatically.
7-
var currentVersion = "1.15";
7+
var currentVersion = "1.16";
88

99
var tabQueue = {}; // windowId -> Array
1010
var keyQueue = ""; // Queue of keys typed
1111
var validFirstKeys = {};
1212
var singleKeyCommands = [];
1313

14-
var specialKeyStrokeRegex = /^<(a|m|c)-.>/;
14+
var hasModifierRegex = /^<[amc]-.>/;
1515

1616
var defaultSettings = {
1717
scrollStepSize: 60,
@@ -142,6 +142,66 @@
142142
returnPort.postMessage({ zoomLevel: zoomLevel });
143143
}
144144

145+
function showHelp() {
146+
chrome.tabs.getSelected(null, function(tab) {
147+
chrome.tabs.sendRequest(tab.id, { name: "showHelpDialog", dialogHtml: helpDialogHtml() });
148+
});
149+
}
150+
151+
/*
152+
* Retrieves the help dialog HTML template from a file, and populates it with the latest keybindings.
153+
*/
154+
function helpDialogHtml(showUnboundCommands, showCommandNames, customTitle) {
155+
var commandsToKey = {};
156+
for (var key in keyToCommandRegistry) {
157+
var command = keyToCommandRegistry[key].command;
158+
commandsToKey[command] = (commandsToKey[command] || []).concat(key);
159+
}
160+
var dialogHtml = fetchFileContents("helpDialog.html");
161+
for (var group in commandGroups)
162+
dialogHtml = dialogHtml.replace("{{" + group + "}}",
163+
helpDialogHtmlForCommandGroup(group, commandsToKey, availableCommands,
164+
showUnboundCommands, showCommandNames));
165+
dialogHtml = dialogHtml.replace("{{version}}", currentVersion);
166+
dialogHtml = dialogHtml.replace("{{title}}", customTitle || "Help");
167+
return dialogHtml;
168+
}
169+
170+
/*
171+
* Generates HTML for a given set of commands. commandGroups are defined in commands.js
172+
*/
173+
function helpDialogHtmlForCommandGroup(group, commandsToKey, availableCommands,
174+
showUnboundCommands, showCommandNames) {
175+
var html = [];
176+
for (var i = 0; i < commandGroups[group].length; i++) {
177+
var command = commandGroups[group][i];
178+
bindings = (commandsToKey[command] || [""]).join(", ")
179+
if (showUnboundCommands || commandsToKey[command])
180+
{
181+
html.push("<tr><td>", escapeHtml(bindings),
182+
"</td><td>:</td><td>", availableCommands[command].description);
183+
184+
if (showCommandNames)
185+
html.push("<span class='commandName'>(" + command + ")</span>");
186+
187+
html.push("</td></tr>");
188+
}
189+
}
190+
return html.join("\n");
191+
}
192+
193+
function escapeHtml(string) { return string.replace(/</g, "&lt;").replace(/>/g, "&gt;"); }
194+
195+
/*
196+
* Fetches the contents of a file bundled with this extension.
197+
*/
198+
function fetchFileContents(extensionFileName) {
199+
var req = new XMLHttpRequest();
200+
req.open("GET", chrome.extension.getURL(extensionFileName), false); // false => synchronous
201+
req.send();
202+
return req.responseText;
203+
}
204+
145205
/**
146206
* Returns the keys that can complete a valid command given the current key queue.
147207
*/
@@ -278,14 +338,14 @@
278338
// End action functions
279339

280340
function splitKeyIntoFirstAndSecond(key) {
281-
if (key.search(specialKeyStrokeRegex) == 0)
341+
if (key.search(hasModifierRegex) == 0)
282342
return { first: key.slice(0, 5), second: key.slice(5) };
283343
else
284344
return { first: key[0], second: key.slice(1) };
285345
}
286346

287347
function getActualKeyStrokeLength(key) {
288-
if (key.search(specialKeyStrokeRegex) == 0)
348+
if (key.search(hasModifierRegex) == 0)
289349
return 1 + getActualKeyStrokeLength(key.slice(5));
290350
else
291351
return key.length;
@@ -295,9 +355,7 @@
295355
for (var key in keyToCommandRegistry)
296356
{
297357
if (getActualKeyStrokeLength(key) == 2)
298-
{
299358
validFirstKeys[splitKeyIntoFirstAndSecond(key).first] = true;
300-
}
301359
}
302360
}
303361

@@ -309,6 +367,16 @@
309367
}
310368
}
311369

370+
function refreshCompletionKeysAfterMappingSave() {
371+
validFirstKeys = {};
372+
singleKeyCommands = [];
373+
374+
populateValidFirstKeys();
375+
populateSingleKeyCommands();
376+
377+
sendRequestToAllTabs({ name: "refreshCompletionKeys", completionKeys: generateCompletionKeys() });
378+
}
379+
312380
/*
313381
* Generates a list of keys that can complete a valid command given the current key queue or the one passed
314382
* in.
@@ -438,6 +506,8 @@
438506
}
439507

440508
function init() {
509+
clearKeyMappingsAndSetDefaults();
510+
441511
if (localStorage["keyMappings"])
442512
parseCustomKeyMappings(localStorage["keyMappings"]);
443513

@@ -446,7 +516,6 @@
446516
if (shouldShowUpgradeMessage())
447517
sendRequestToAllTabs({ name: "showUpgradeNotification", version: currentVersion });
448518
}
449-
450519
init();
451520
</script>
452521
</head>

commands.js

Lines changed: 95 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -51,84 +51,103 @@ function parseCustomKeyMappings(customKeyMappings) {
5151
}
5252
}
5353

54+
function clearKeyMappingsAndSetDefaults() {
55+
keyToCommandRegistry = {};
56+
57+
mapKeyToCommand('?', 'showHelp');
58+
mapKeyToCommand('j', 'scrollDown');
59+
mapKeyToCommand('k', 'scrollUp');
60+
mapKeyToCommand('h', 'scrollLeft');
61+
mapKeyToCommand('l', 'scrollRight');
62+
mapKeyToCommand('gg', 'scrollToTop');
63+
mapKeyToCommand('G', 'scrollToBottom');
64+
mapKeyToCommand('<c-e>', 'scrollDown');
65+
mapKeyToCommand('<c-y>', 'scrollUp');
66+
mapKeyToCommand('<c-d>', 'scrollPageDown');
67+
mapKeyToCommand('<c-u>', 'scrollPageUp');
68+
mapKeyToCommand('<c-f>', 'scrollFullPageDown');
69+
mapKeyToCommand('<c-b>', 'scrollFullPageUp');
70+
mapKeyToCommand('r', 'reload');
71+
mapKeyToCommand('gf', 'toggleViewSource');
72+
73+
mapKeyToCommand('i', 'enterInsertMode');
74+
75+
mapKeyToCommand('H', 'goBack');
76+
mapKeyToCommand('L', 'goForward');
77+
78+
mapKeyToCommand('zi', 'zoomIn');
79+
mapKeyToCommand('zo', 'zoomOut');
80+
81+
mapKeyToCommand('f', 'activateLinkHintsMode');
82+
mapKeyToCommand('F', 'activateLinkHintsModeToOpenInNewTab');
83+
84+
mapKeyToCommand('/', 'enterFindMode');
85+
mapKeyToCommand('n', 'performFind');
86+
mapKeyToCommand('N', 'performBackwardsFind');
87+
88+
mapKeyToCommand('yy', 'copyCurrentUrl');
89+
90+
mapKeyToCommand('K', 'nextTab');
91+
mapKeyToCommand('J', 'previousTab');
92+
mapKeyToCommand('gt', 'nextTab');
93+
mapKeyToCommand('gT', 'previousTab');
94+
95+
mapKeyToCommand('t', 'createTab');
96+
mapKeyToCommand('d', 'removeTab');
97+
mapKeyToCommand('u', 'restoreTab');
98+
}
99+
54100
// Navigating the current page:
55-
addCommand('scrollDown', 'Scroll down.');
56-
addCommand('scrollUp', 'Scroll up.');
57-
addCommand('scrollLeft', 'Scroll left.');
58-
addCommand('scrollRight', 'Scroll right.');
59-
addCommand('scrollToTop', 'Scroll to the top of the page.');
60-
addCommand('scrollToBottom', 'Scroll to the bottom of the page.');
61-
addCommand('scrollPageDown', 'Scroll a page up.');
62-
addCommand('scrollPageUp', 'Scroll a page down.');
63-
addCommand('scrollFullPageDown', 'Scroll a full page down.');
64-
addCommand('scrollFullPageUp', 'Scroll a full page up.');
65-
66-
addCommand('reload', 'Reload the page.');
67-
addCommand('toggleViewSource', 'View page source.');
68-
addCommand('zoomIn', 'Zoom in.');
69-
addCommand('zoomOut', 'Zoom out.');
70-
addCommand('copyCurrentUrl', 'Copy the current URL to the clipboard.');
71-
72-
addCommand('enterInsertMode', 'Enter insert mode.');
73-
74-
addCommand('activateLinkHintsMode', 'Enter link hints mode to open links in current tab.');
75-
addCommand('activateLinkHintsModeToOpenInNewTab', 'Enter link hints mode to open links in new tab.');
76-
77-
addCommand('enterFindMode', 'Enter find mode.');
78-
addCommand('performFind', 'Cycle forward to the next find match.');
79-
addCommand('performBackwardsFind', 'Cycle backward to the previous find match.');
101+
addCommand('showHelp', 'Show help', true);
102+
addCommand('scrollDown', 'Scroll down');
103+
addCommand('scrollUp', 'Scroll up');
104+
addCommand('scrollLeft', 'Scroll left');
105+
addCommand('scrollRight', 'Scroll right');
106+
addCommand('scrollToTop', 'Scroll to the top of the page');
107+
addCommand('scrollToBottom', 'Scroll to the bottom of the page');
108+
addCommand('scrollPageDown', 'Scroll a page up');
109+
addCommand('scrollPageUp', 'Scroll a page down');
110+
addCommand('scrollFullPageDown', 'Scroll a full page down');
111+
addCommand('scrollFullPageUp', 'Scroll a full page up');
112+
113+
addCommand('reload', 'Reload the page');
114+
addCommand('toggleViewSource', 'View page source');
115+
addCommand('zoomIn', 'Zoom in');
116+
addCommand('zoomOut', 'Zoom out');
117+
addCommand('copyCurrentUrl', 'Copy the current URL to the clipboard');
118+
119+
addCommand('enterInsertMode', 'Enter insert mode');
120+
121+
addCommand('activateLinkHintsMode', 'Enter link hints mode to open links in current tab');
122+
addCommand('activateLinkHintsModeToOpenInNewTab', 'Enter link hints mode to open links in new tab');
123+
124+
addCommand('enterFindMode', 'Enter find mode');
125+
addCommand('performFind', 'Cycle forward to the next find match');
126+
addCommand('performBackwardsFind', 'Cycle backward to the previous find match');
80127

81128
// Navigating your history:
82-
addCommand('goBack', 'Go back in history.');
83-
addCommand('goForward', 'Go forward in history.');
129+
addCommand('goBack', 'Go back in history');
130+
addCommand('goForward', 'Go forward in history');
84131

85132
// Manipulating tabs:
86-
addCommand('nextTab', 'Go one tab right.', true);
87-
addCommand('previousTab', 'Go one tab left.', true);
88-
addCommand('createTab', 'Create new tab.', true);
89-
addCommand('removeTab', 'Close current tab.', true);
90-
addCommand('restoreTab', "Restore closed tab. (i.e. unwind the 'd' command).", true);
91-
92-
mapKeyToCommand('j', 'scrollDown');
93-
mapKeyToCommand('k', 'scrollUp');
94-
mapKeyToCommand('h', 'scrollLeft');
95-
mapKeyToCommand('l', 'scrollRight');
96-
mapKeyToCommand('gg', 'scrollToTop');
97-
mapKeyToCommand('G', 'scrollToBottom');
98-
mapKeyToCommand('<c-e>', 'scrollDown');
99-
mapKeyToCommand('<c-y>', 'scrollUp');
100-
mapKeyToCommand('<c-d>', 'scrollPageDown');
101-
mapKeyToCommand('<c-u>', 'scrollPageUp');
102-
mapKeyToCommand('<c-f>', 'scrollFullPageDown');
103-
mapKeyToCommand('<c-b>', 'scrollFullPageUp');
104-
mapKeyToCommand('r', 'reload');
105-
mapKeyToCommand('gf', 'toggleViewSource');
106-
107-
mapKeyToCommand('i', 'enterInsertMode');
108-
109-
mapKeyToCommand('ba', 'goBack');
110-
mapKeyToCommand('H', 'goBack');
111-
mapKeyToCommand('fw', 'goForward');
112-
mapKeyToCommand('fo', 'goForward');
113-
mapKeyToCommand('L', 'goForward');
114-
115-
mapKeyToCommand('zi', 'zoomIn');
116-
mapKeyToCommand('zo', 'zoomOut');
117-
118-
mapKeyToCommand('f', 'activateLinkHintsMode');
119-
mapKeyToCommand('F', 'activateLinkHintsModeToOpenInNewTab');
120-
121-
mapKeyToCommand('/', 'enterFindMode');
122-
mapKeyToCommand('n', 'performFind');
123-
mapKeyToCommand('N', 'performBackwardsFind');
124-
125-
mapKeyToCommand('yy', 'copyCurrentUrl');
126-
127-
mapKeyToCommand('K', 'nextTab');
128-
mapKeyToCommand('J', 'previousTab');
129-
mapKeyToCommand('gt', 'nextTab');
130-
mapKeyToCommand('gT', 'previousTab');
131-
132-
mapKeyToCommand('t', 'createTab');
133-
mapKeyToCommand('d', 'removeTab');
134-
mapKeyToCommand('u', 'restoreTab');
133+
addCommand('nextTab', 'Go one tab right', true);
134+
addCommand('previousTab', 'Go one tab left', true);
135+
addCommand('createTab', 'Create new tab', true);
136+
addCommand('removeTab', 'Close current tab', true);
137+
addCommand('restoreTab', "Restore closed tab", true);
138+
139+
140+
// An ordered listing of all available commands, grouped by type. This is the order they will
141+
// be shown in the help page.
142+
var commandGroups = {
143+
pageNavigation:
144+
["scrollDown", "scrollUp", "scrollLeft", "scrollRight",
145+
"scrollToTop", "scrollToBottom", "scrollPageDown", "scrollPageUp", "scrollFullPageDown",
146+
"reload", "toggleViewSource", "zoomIn", "zoomOut", "copyCurrentUrl",
147+
"enterInsertMode", "activateLinkHintsMode", "activateLinkHintsModeToOpenInNewTab",
148+
"enterFindMode", "performFind", "performBackwardsFind"],
149+
historyNavigation:
150+
["goBack", "goForward"],
151+
tabManipulation:
152+
["nextTab", "previousTab", "createTab", "removeTab", "restoreTab"]
153+
};

0 commit comments

Comments
 (0)