aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.markdown3
-rw-r--r--background_page.html8
-rw-r--r--commands.js23
-rw-r--r--helpDialog.html11
-rw-r--r--test_harnesses/form.html4
-rw-r--r--vimiumFrontend.js29
6 files changed, 63 insertions, 15 deletions
diff --git a/README.markdown b/README.markdown
index dff5f8da..b470da2a 100644
--- a/README.markdown
+++ b/README.markdown
@@ -83,7 +83,8 @@ Release Notes
1.20 (Unreleased)
- In link hints mode, holding down the shift key will now toggle between opening in the current tab and opening in a new tab.
-- Two new commands to scroll to the left and right edges of the page bound to zH and zL respectively.
+- Two new commands (`zH` and `zL`) to scroll to the left and right edges of the page.
+- A new command (`gi`) to focus the first (or n-th) text input box on the page.
- Frame support.
- Bug fixes.
diff --git a/background_page.html b/background_page.html
index fb1eb48b..b862a881 100644
--- a/background_page.html
+++ b/background_page.html
@@ -524,8 +524,12 @@
if (!registryEntry.isBackgroundCommand) {
var port = chrome.tabs.connect(tabId, { name: "executePageCommand" });
- port.postMessage({ command: registryEntry.command, count: count, frameId: frameId,
- completionKeys: generateCompletionKeys("") });
+ port.postMessage({ command: registryEntry.command,
+ frameId: frameId,
+ count: count,
+ passCountToFunction: registryEntry.passCountToFunction,
+ completionKeys: generateCompletionKeys("")
+ });
refreshedCompletionKeys = true;
} else {
diff --git a/commands.js b/commands.js
index e49574e3..635c5350 100644
--- a/commands.js
+++ b/commands.js
@@ -1,14 +1,17 @@
var availableCommands = {};
var keyToCommandRegistry = {};
-function addCommand(command, description, isBackgroundCommand) {
+function addCommand(command, description, isBackgroundCommand, passCountToFunction) {
if (availableCommands[command])
{
console.log(command, "is already defined! Check commands.js for duplicates.");
return;
}
- availableCommands[command] = { description: description, isBackgroundCommand: isBackgroundCommand };
+ availableCommands[command] = { description: description,
+ isBackgroundCommand: isBackgroundCommand,
+ passCountToFunction: passCountToFunction
+ };
}
function mapKeyToCommand(key, command) {
@@ -18,7 +21,10 @@ function mapKeyToCommand(key, command) {
return;
}
- keyToCommandRegistry[key] = { command: command, isBackgroundCommand: availableCommands[command].isBackgroundCommand };
+ keyToCommandRegistry[key] = { command: command,
+ isBackgroundCommand: availableCommands[command].isBackgroundCommand,
+ passCountToFunction: availableCommands[command].passCountToFunction
+ };
}
function unmapKey(key) { delete keyToCommandRegistry[key]; }
@@ -80,7 +86,6 @@ function clearKeyMappingsAndSetDefaults() {
mapKeyToCommand('k', 'scrollUp');
mapKeyToCommand('h', 'scrollLeft');
mapKeyToCommand('l', 'scrollRight');
-
mapKeyToCommand('gg', 'scrollToTop');
mapKeyToCommand('G', 'scrollToBottom');
mapKeyToCommand('zH', 'scrollToLeft');
@@ -103,6 +108,8 @@ function clearKeyMappingsAndSetDefaults() {
mapKeyToCommand('zi', 'zoomIn');
mapKeyToCommand('zo', 'zoomOut');
+ mapKeyToCommand('gi', 'focusInput');
+
mapKeyToCommand('f', 'activateLinkHintsMode');
mapKeyToCommand('F', 'activateLinkHintsModeToOpenInNewTab');
@@ -147,6 +154,8 @@ addCommand('copyCurrentUrl', 'Copy the current URL to the clipboard');
addCommand('enterInsertMode', 'Enter insert mode');
+addCommand('focusInput', 'Focus the first (or n-th) text box on the page', false, true);
+
addCommand('activateLinkHintsMode', 'Enter link hints mode to open links in current tab');
addCommand('activateLinkHintsModeToOpenInNewTab', 'Enter link hints mode to open links in new tab');
@@ -176,9 +185,11 @@ addCommand('nextFrame', "Cycle forward to the next frame on the page",
var commandGroups = {
pageNavigation:
["scrollDown", "scrollUp", "scrollLeft", "scrollRight",
- "scrollToTop", "scrollToBottom", "scrollToLeft", "scrollToRight", "scrollPageDown", "scrollPageUp", "scrollFullPageDown",
+ "scrollToTop", "scrollToBottom", "scrollToLeft", "scrollToRight", "scrollPageDown",
+ "scrollPageUp", "scrollFullPageDown",
"reload", "toggleViewSource", "zoomIn", "zoomOut", "copyCurrentUrl", "goUp",
- "enterInsertMode", "activateLinkHintsMode", "activateLinkHintsModeToOpenInNewTab",
+ "enterInsertMode", "focusInput",
+ "activateLinkHintsMode", "activateLinkHintsModeToOpenInNewTab",
"enterFindMode", "performFind", "performBackwardsFind", "nextFrame"],
historyNavigation:
["goBack", "goForward"],
diff --git a/helpDialog.html b/helpDialog.html
index 65fe6a41..ee35fc9b 100644
--- a/helpDialog.html
+++ b/helpDialog.html
@@ -4,7 +4,12 @@
-->
<div id="vimiumHelpDialog">
<style>
- #vimiumHelpDialog * { font-size:12px; line-height:130%; color:black; background-color:transparent; }
+ #vimiumHelpDialog * {
+ font-size:12px;
+ line-height:130%;
+ color:black;
+ background-color:transparent;
+ }
#vimiumHelpDialog {
text-align:left;
border:3px solid red;
@@ -105,12 +110,12 @@
<div id="vimiumHelpDialogFooter">
<div class="vimiumColumn">
Enjoying Vimium?
- <a href="https://chrome.google.com/extensions/detail/dbepggeogbaibhgnhhndojpepiihcmeb">Leave us feedback</a>.<br/>
+ <a href="https://chrome.google.com/extensions/detail/dbepggeogbaibhgnhhndojpepiihcmeb">Leave us
+ feedback</a>.<br/>
Found a bug? <a href="http://github.com/philc/vimium/issues">Report it here</a>.
</div>
<div class="vimiumColumn" style="text-align:right">
<span>Version {{version}}</span><br/>
- <!-- <a href="#">Homepage</a> -->
</div>
</div>
</div>
diff --git a/test_harnesses/form.html b/test_harnesses/form.html
index 52ac9308..740edb46 100644
--- a/test_harnesses/form.html
+++ b/test_harnesses/form.html
@@ -9,9 +9,11 @@
<form action="#">
<p>
Text: <input type="text" name="text" value="" />
+ Text 2: <input type="text" name="text" value="" />
</p>
<p>
Search: <input type="search" />
+ Search 2: <input type="search" />
</p>
<p>
Radio:<br/>
@@ -32,4 +34,4 @@
</p>
</form>
</body>
-</html> \ No newline at end of file
+</html>
diff --git a/vimiumFrontend.js b/vimiumFrontend.js
index ac7d366a..3b73144a 100644
--- a/vimiumFrontend.js
+++ b/vimiumFrontend.js
@@ -84,7 +84,11 @@ function initializePreDomReady() {
if (port.name == "executePageCommand") {
port.onMessage.addListener(function(args) {
if (this[args.command] && frameId == args.frameId) {
- for (var i = 0; i < args.count; i++) { this[args.command].call(); }
+ if (args.passCountToFunction) {
+ this[args.command].call(null, args.count);
+ } else {
+ for (var i = 0; i < args.count; i++) { this[args.command].call(); }
+ }
}
refreshCompletionKeys(args.completionKeys);
@@ -239,6 +243,26 @@ function scrollFullPageDown() { window.scrollBy(0, window.innerHeight); }
function scrollLeft() { window.scrollBy(-1 * settings["scrollStepSize"], 0); }
function scrollRight() { window.scrollBy(settings["scrollStepSize"], 0); }
+function focusInput(count) {
+ var xpath = '//input[@type="text" or @type="search"]';
+ var results = document.evaluate(xpath, document.documentElement, null,
+ XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
+
+ var lastInputBox;
+ var i = 0;
+
+ while (i < count) {
+ i += 1;
+
+ var currentInputBox = results.iterateNext();
+ if (!currentInputBox) { break; }
+
+ lastInputBox = currentInputBox;
+ }
+
+ if (lastInputBox) { lastInputBox.focus(); }
+}
+
function reload() { window.location.reload(); }
function goBack() { history.back(); }
function goForward() { history.forward(); }
@@ -535,7 +559,8 @@ function hideHelpDialog(clickEvent) {
var helpDialog = document.getElementById("vimiumHelpDialogContainer");
if (helpDialog)
helpDialog.parentNode.removeChild(helpDialog);
- clickEvent.preventDefault();
+ if (clickEvent)
+ clickEvent.preventDefault();
}
/*