From ce2093fcfef6f7000edc7eae026c7d529273199d Mon Sep 17 00:00:00 2001 From: Phil Crosby Date: Sun, 5 Sep 2010 15:38:37 -0700 Subject: Implemented "gi" feature to focus first input element Conflicts: commands.js --- commands.js | 11 ++++++++--- vimiumFrontend.js | 13 +++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/commands.js b/commands.js index 477e5cd3..26ef2d34 100644 --- a/commands.js +++ b/commands.js @@ -80,7 +80,6 @@ function clearKeyMappingsAndSetDefaults() { mapKeyToCommand('k', 'scrollUp'); mapKeyToCommand('h', 'scrollLeft'); mapKeyToCommand('l', 'scrollRight'); - mapKeyToCommand('gg', 'scrollToTop'); mapKeyToCommand('G', 'scrollToBottom'); mapKeyToCommand('zH', 'scrollToLeft'); @@ -103,6 +102,8 @@ function clearKeyMappingsAndSetDefaults() { mapKeyToCommand('zi', 'zoomIn'); mapKeyToCommand('zo', 'zoomOut'); + mapKeyToCommand('gi', 'focusFirstInput'); + mapKeyToCommand('f', 'activateLinkHintsMode'); mapKeyToCommand('F', 'activateLinkHintsModeToOpenInNewTab'); @@ -145,6 +146,8 @@ addCommand('copyCurrentUrl', 'Copy the current URL to the clipboard'); addCommand('enterInsertMode', 'Enter insert mode'); +addCommand('focusFirstInput', 'Focus the first text box on the page.'); + addCommand('activateLinkHintsMode', 'Enter link hints mode to open links in current tab'); addCommand('activateLinkHintsModeToOpenInNewTab', 'Enter link hints mode to open links in new tab'); @@ -172,9 +175,11 @@ addCommand('restoreTab', "Restore closed tab", true); 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", "focusFirstInput", + "activateLinkHintsMode", "activateLinkHintsModeToOpenInNewTab", "enterFindMode", "performFind", "performBackwardsFind"], historyNavigation: ["goBack", "goForward"], diff --git a/vimiumFrontend.js b/vimiumFrontend.js index e288714a..f2f5abd3 100644 --- a/vimiumFrontend.js +++ b/vimiumFrontend.js @@ -198,6 +198,19 @@ function scrollFullPageDown() { window.scrollBy(0, window.innerHeight); } function scrollLeft() { window.scrollBy(-1 * settings["scrollStepSize"], 0); } function scrollRight() { window.scrollBy(settings["scrollStepSize"], 0); } +function focusFirstInput() { + var xpath = '//input[@type="text" or @type="search"]'; + var result = document.evaluate( xpath, document.documentElement, null, + XPathResult.FIRST_ORDERED_NODE_TYPE, null ); + + if ( result.singleNodeValue == null ) return; + + var el = document.getElementById( result.singleNodeValue.id ); + if ( el ) { + el.focus(); + } +} + function reload() { window.location.reload(); } function goBack() { history.back(); } function goForward() { history.forward(); } -- cgit v1.2.3