diff options
| -rw-r--r-- | CREDITS | 1 | ||||
| -rw-r--r-- | README.markdown | 95 | ||||
| -rw-r--r-- | background_page.html | 55 | ||||
| -rw-r--r-- | commands.js | 9 | ||||
| -rw-r--r-- | manifest.json | 2 | ||||
| -rw-r--r-- | vimiumFrontend.js | 54 |
6 files changed, 143 insertions, 73 deletions
@@ -23,5 +23,6 @@ Contributors: Svein-Erik Larsen <feinom@gmail.com> (github: feinom) Bill Casarin <jb@jb55.com> (github: jb55) R.T. Lechow <rtlechow@gmail.com> (github: rtlechow) + Justin Blake <justin@hentzia.com> (github: blaix) Feel free to add real names in addition to GitHub usernames. diff --git a/README.markdown b/README.markdown index fcf50fad..3d7a5800 100644 --- a/README.markdown +++ b/README.markdown @@ -11,27 +11,30 @@ You can install the stable version of Vimium from the Alternatively, you can install it from source: -1. Navigate to chrome://extensions -2. Click on "Load Extension..." -3. Select the vimium directory. +1. Navigate to `chrome://extensions` +2. Toggle into Developer Mode +3. Click on "Load Unpacked Extension..." +4. Select the Vimium directory. -The Settings page can be found by clicking the Options button next to Vimium on chrome://extensions. +The Options page can be reached via a link on the help dialog (hit `?`) or via the button next to Vimium on +the Chrome Extensions page (`chrome://extensions`). Keyboard Bindings ----------------- -Modifier keys are specified as <c-x>, <m-x>, <a-x> for ctrl+x, meta+x, and alt+x -respectively. You can change any of these shortcuts under "Advanced Options". +Modifier keys are specified as <c-x> <m-x>, <a-x> for ctrl+x, meta+x, and alt+x +respectively. See the next section for instructions on modifying these bindings. Navigating the current page: + ? show the help dialog for a list of all available keys h scroll left j scroll down k scroll up l scroll right gg scroll to top of the page G scroll to bottom of the page - d, <c-d> scroll down half a page - u, <c-u> scroll up half a page + d scroll down half a page + u scroll up half a page f open a link in the current tab F open a link in a new tab r reload @@ -67,14 +70,47 @@ Additional advanced browsing commands: zH scroll all the way left zL scroll all the way right z0 reset zoom to default value - <c-f> scroll down a full page - <c-b> scroll up a full page Vimium supports command repetition so, for example, hitting '5t' will open 5 tabs in rapid succession. ESC (or -<c-[>) will clear any partial commands in the queue. +<c-[>) will clear any partial commands in the queue and will also exit insert and find modes. +Custom Key Mappings +------------------- + +You may remap or unmap any of the default key bindings in the "Key mappings" section under "Advanced Options" +on the options page. + +Enter one of the following key mapping commands per line: + +- `map key command`: Maps a key to a Vimium command. Overrides Chrome's default behavior (if any). +- `unmap key`: Unmaps a key and restores Chrome's default behavior (if any). +- `unmapAll`: Unmaps all bindings. This is useful if you want to completely wipe Vimium's defaults and start + from scratch with your own setup. + +Examples: + +- `map <c-d> scrollPageDown` maps ctrl+d to scrolling the page down. Chrome's default behavior of bringing up + a bookmark dialog is suppressed. +- `map r reload` maps the r key to reloading the page. +- `unmap <c-d>` removes any mapping for ctrl+d and restores Chrome's default behavior. +- `unmap r` removes any mapping for the r key. + +Available Vimium commands can be found via the "Show Available Commands" link near the key mapping box. The +command name appears to the right of the description in parenthesis. + +You can add comments to your key mappings by starting a line with `"` or `#`. + +The following special keys are available for mapping: + +- `<c-*>`, `<a-*>`, `<m-*>` for ctrl, alt, and meta (command on Mac) respectively with any key. Replace `*` + with the key of choice. +- `<left>`, `<right>`, `<up>`, `<down>` for the arrow keys +- `<f1>` through `<f12>` for the function keys + +Shifts are automatically detected so, for example, `<c-&>` corresponds to ctrl+shift+7 on an English keyboard. + Contributing ------------ @@ -84,7 +120,8 @@ discussion on the issues tracker or on the [mailing list][list_url]. If it mirro another browser or in Vim itself, let us know! Once you've picked something to work on, add a comment to the respective issue so others don't duplicate your effort. -When you're done, send us a pull request on Github. Feel free to include a change to the CREDITS file with your patch. +When you're done, send us a pull request on Github. Feel free to include a change to the CREDITS file with +your patch. [list_url]: http://groups.google.com/group/vimium-dev?hl=en @@ -94,13 +131,23 @@ don't exceed 110 characters. Release Notes ------------- +1.27 (03/24/2011) + +- Improvements and bugfixes. + +1.26 (02/17/2011) + +- `<c-d>`, `<c-f>` and related are no longer bound by default. You can rebind them on the options page. +- Faster link hinting. + 1.22, 1.23, 1.24, 1.25 (02/10/2011) - Some sites are now excluded by default. - View source (`gs`) now opens in a new tab. - Support for browsing paginated sites using `]]` and `[[` to go forward and backward respectively. - `z0` will reset the zoom level for the current page. -- Many of the less-used commands are now marked as "advanced" and hidden in the help dialog by default, so that the core command set is more focused and approachable. +- Many of the less-used commands are now marked as "advanced" and hidden in the help dialog by default, so + that the core command set is more focused and approachable. - Improvements to link hinting. - Bugfixes. @@ -110,7 +157,8 @@ Release Notes 1.20 (10/24/2010) -- In link hints mode, holding down the shift key will now toggle between opening in the current tab and opening in a new tab. +- 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 (`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. - A new command (`<a-f>`) to open up multiple links at a time in new tabs. @@ -127,13 +175,17 @@ Release Notes - Vimium now runs on pages with file:/// and ftp:/// - The Options page is now linked from the Help dialog. -- Arrow keys and function keys can now be mapped using <left>, <right>, <up>, <down>, <f1>, <f2>, etc. in the mappings interface. -- There is a new command `goUp` (mapped to `gu` by default) that will go up one level in the URL hierarchy. For example: from http://vimium.github.com/foo/bar to http://vimium.github.com/foo. At the moment, `goUp` does not support command repetition. +- Arrow keys and function keys can now be mapped using <left>, <right>, <up>, <down>, + <f1>, <f2>, etc. in the mappings interface. +- There is a new command `goUp` (mapped to `gu` by default) that will go up one level in the URL hierarchy. + For example: from http://vimium.github.com/foo/bar to http://vimium.github.com/foo. At the moment, `goUp` +does not support command repetition. - Bug fixes and optimizations. 1.17 (04/18/2010) -- 'u' now restores tabs that were closed by the mouse or with native shortcuts. Tabs are also restored in their prior position. +- 'u' now restores tabs that were closed by the mouse or with native shortcuts. Tabs are also restored in + their prior position. - New 'unmapAll' command in the key mappings interface to remove all default mappings. - Link hints are now faster and more reliable. - Bug fixes. @@ -157,12 +209,12 @@ Release Notes 1.13 (01/21/2010) -- <c-f> and <c-b> are now mapped to scroll a full page up or down respectively. +- `<c-f>` and `<c-b>` are now mapped to scroll a full page up or down respectively. - Bugfixes related to entering insert mode when the page first loads, and when focusing Flash embeds. - Added command listing to the Options page for easy reference. - J & K have reversed for tab switching: J goes left and K goes right. -- <c-[> is now equivalent to ESC, to match the behavior of VIM. -- <c-e> & <c-y> are now mapped to scroll down and up respectively. +- `<c-[>` is now equivalent to ESC, to match the behavior of VIM. +- `<c-e>` and `<c-y>` are now mapped to scroll down and up respectively. - The characters used for link hints are now configurable under Advanced Options. 1.11, 1.12 (01/08/2010) @@ -176,7 +228,8 @@ Release Notes 1.1 (01/03/2010) - A nicer looking settings page. -- An exclusion list that allows you to define URL patterns for which Vimium will be disabled (e.g. http\*://mail.google.com/\*). +- An exclusion list that allows you to define URL patterns for which Vimium will be disabled (e.g. + http\*://mail.google.com/\*). - Vimium-interpreted keystrokes are no longer sent to the page. - Better Windows support. - Various miscellaneous bug fixes and UI improvements. diff --git a/background_page.html b/background_page.html index ba459f53..71bbcf7a 100644 --- a/background_page.html +++ b/background_page.html @@ -71,7 +71,7 @@ }; var sendRequestHandlers = { - getCompletionKeys: getCompletionKeys, + getCompletionKeys: getCompletionKeysRequest, getLinkHintCss: getLinkHintCss, openUrlInNewTab: openUrlInNewTab, openUrlInCurrentTab: openUrlInCurrentTab, @@ -236,8 +236,11 @@ /** * Returns the keys that can complete a valid command given the current key queue. */ - function getCompletionKeys(request) { - return {completionKeys: generateCompletionKeys()}; + function getCompletionKeysRequest(request) { + return { name: "refreshCompletionKeys", + completionKeys: generateCompletionKeys(), + validFirstKeys: validFirstKeys + }; } /** @@ -374,6 +377,8 @@ function updateOpenTabs(tab) { openTabs[tab.id] = { url: tab.url, positionIndex: tab.index, windowId: tab.windowId }; + // Frames are recreated on refresh + delete framesForTab[tab.id]; } function handleUpdateScrollPosition(request, sender) { @@ -508,7 +513,7 @@ populateValidFirstKeys(); populateSingleKeyCommands(); - sendRequestToAllTabs({ name: "refreshCompletionKeys", completionKeys: generateCompletionKeys() }); + sendRequestToAllTabs(getCompletionKeysRequest()); } /* @@ -580,7 +585,11 @@ refreshedCompletionKeys = true; } else { - repeatFunction(this[registryEntry.command], count, 0, frameId); + if(registryEntry.passCountToFunction){ + this[registryEntry.command](count); + } else { + repeatFunction(this[registryEntry.command], count, 0, frameId); + } } newKeyQueue = ""; @@ -598,10 +607,8 @@ // If we haven't sent the completion keys piggybacked on executePageCommand, // send them by themselves. - if (!refreshedCompletionKeys) - { - var port = chrome.tabs.connect(tabId, { name: "refreshCompletionKeys" }); - port.postMessage({ completionKeys: generateCompletionKeys(newKeyQueue) }); + if (!refreshedCompletionKeys) { + chrome.tabs.sendRequest(tabId, getCompletionKeysRequest(), null); } return newKeyQueue; @@ -654,7 +661,7 @@ if (!framesForTab[sender.tab.id]) framesForTab[sender.tab.id] = { frames: [] }; - if (request.top) { + if (request.is_top) { focusedFrame = request.frameId; framesForTab[sender.tab.id].total = request.total; } @@ -687,25 +694,29 @@ focusedFrame = request.frameId; } - function nextFrame(callback, frameId) { + function nextFrame(count) { chrome.tabs.getSelected(null, function(tab) { - var index; var frames = framesForTab[tab.id].frames; + var curr_index = getCurrFrameIndex(frames); - for (index=0; index < frames.length; index++) { - if (frames[index].id == focusedFrame) - break; - } - - if (index >= frames.length-1) - index = 0; - else - index++; + // TODO: Skip the "top" frame (which doesn't actually have a <frame> tag), + // since it exists only to contain the other frames. + var new_index = (curr_index + count) % frames.length; - chrome.tabs.sendRequest(tab.id, { name: "focusFrame", frameId: frames[index].id, highlight: true }); + chrome.tabs.sendRequest(tab.id, { name: "focusFrame", frameId: frames[new_index].id, highlight: true }); }); } + function getCurrFrameIndex(frames) { + var index; + for (index=0; index < frames.length; index++) { + if (frames[index].id == focusedFrame) + break; + } + return index; + } + + function init() { clearKeyMappingsAndSetDefaults(); diff --git a/commands.js b/commands.js index b5d0a359..d4613c12 100644 --- a/commands.js +++ b/commands.js @@ -100,15 +100,8 @@ function clearKeyMappingsAndSetDefaults() { "<c-e>": "scrollDown", "<c-y>": "scrollUp", - // scrollPageDown and scrollPageUp are mapped to two keys because they are very common actions so we - // want them to be mapped without a modifier key, but we also want to be faithful to Vim convention which - // has them on ctrl+D and ctrl+U. "d": "scrollPageDown", "u": "scrollPageUp", - "<c-d>": "scrollPageDown", - "<c-u>": "scrollPageUp", - "<c-f>": "scrollFullPageDown", - "<c-b>": "scrollFullPageUp", "r": "reload", "gs": "toggleViewSource", @@ -213,7 +206,7 @@ var commandDescriptions = { activateBookmarkFindMode: ["Open a bookmark in the current tab"], activateBookmarkFindModeToOpenInNewTab: ["Open a bookmark in a new tab"], - nextFrame: ["Cycle forward to the next frame on the page", { background: true }] + nextFrame: ["Cycle forward to the next frame on the page", { background: true, passCountToFunction: true }] }; for (var command in commandDescriptions) diff --git a/manifest.json b/manifest.json index 3b17a71c..c5a2834d 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "name": "Vimium", - "version": "1.25", + "version": "1.27", "description": "The Hacker's Browser. Vimium provides keyboard shortcuts for navigation and control in the spirit of Vim.", "icons": { "16": "icons/icon16.png", "48": "icons/icon48.png", diff --git a/vimiumFrontend.js b/vimiumFrontend.js index 2428e4aa..eb0216f4 100644 --- a/vimiumFrontend.js +++ b/vimiumFrontend.js @@ -20,6 +20,7 @@ var saveZoomLevelPort; var isEnabledForUrl = true; // The user's operating system. var currentCompletionKeys; +var validFirstKeys; var linkHintCss; // TODO(philc): This should be pulled from the extension's storage when the page loads. @@ -71,6 +72,7 @@ var settings = { frameId = Math.floor(Math.random()*999999999) var hasModifiersRegex = /^<([amc]-)+.>/; +var googleRegex = /:\/\/[^/]*google[^/]+/; /* * Complete initialization work that sould be done prior to DOMReady, like setting the page's zoom level. @@ -94,20 +96,21 @@ function initializePreDomReady() { keyPort = chrome.extension.connect({ name: "keyDown" }); chrome.extension.onRequest.addListener(function(request, sender, sendResponse) { - if (request.name == "hideUpgradeNotification") + if (request.name == "hideUpgradeNotification") { HUD.hideUpgradeNotification(); - else if (request.name == "showUpgradeNotification" && isEnabledForUrl) + } else if (request.name == "showUpgradeNotification" && isEnabledForUrl) { HUD.showUpgradeNotification(request.version); - else if (request.name == "showHelpDialog") + } else if (request.name == "showHelpDialog") { if (isShowingHelpDialog) hideHelpDialog(); else showHelpDialog(request.dialogHtml, request.frameId); - else if (request.name == "focusFrame") - if(frameId == request.frameId) + } else if (request.name == "focusFrame") { + if (frameId == request.frameId) focusThisFrame(request.highlight); - else if (request.name == "refreshCompletionKeys") - refreshCompletionKeys(request.completionKeys); + } else if (request.name == "refreshCompletionKeys") { + refreshCompletionKeys(request); + } sendResponse({}); // Free up the resources used by this open connection. }); @@ -122,7 +125,7 @@ function initializePreDomReady() { } } - refreshCompletionKeys(args.completionKeys); + refreshCompletionKeys(args); }); } else if (port.name == "getScrollPosition") { @@ -203,12 +206,12 @@ function initializeOnDomReady() { }; // This is a little hacky but sometimes the size wasn't available on domReady? -function registerFrameIfSizeAvailable (top) { +function registerFrameIfSizeAvailable (is_top) { if (innerWidth != undefined && innerWidth != 0 && innerHeight != undefined && innerHeight != 0) chrome.extension.sendRequest({ handler: "registerFrame", frameId: frameId, - area: innerWidth * innerHeight, top: top, total: frames.length + 1 }); + area: innerWidth * innerHeight, is_top: is_top, total: frames.length + 1 }); else - setTimeout(function () { registerFrameIfSizeAvailable(top); }, 100); + setTimeout(function () { registerFrameIfSizeAvailable(is_top); }, 100); } /* @@ -431,8 +434,8 @@ function onKeydown(event) { exitInsertMode(); // Added to prevent Google Instant from reclaiming the keystroke and putting us back into the search box. - // TOOD(ilya): Revisit this. Not sure it's the absolute best approach. - event.stopPropagation(); + if (isGoogleSearch()) + event.stopPropagation(); } } else if (findMode) @@ -473,7 +476,8 @@ function onKeydown(event) { // Subject to internationalization issues since we're using keyIdentifier instead of charCode (in keypress). // // TOOD(ilya): Revisit this. Not sure it's the absolute best approach. - if (keyChar == "" && !insertMode && currentCompletionKeys.indexOf(getKeyChar(event)) != -1) + if (keyChar == "" && !insertMode + && (currentCompletionKeys.indexOf(getKeyChar(event)) != -1 || validFirstKeys[getKeyChar(event)])) event.stopPropagation(); } @@ -495,13 +499,21 @@ function checkIfEnabledForUrl() { }); } -function refreshCompletionKeys(completionKeys) { - if (completionKeys) - currentCompletionKeys = completionKeys; - else - chrome.extension.sendRequest({handler: "getCompletionKeys"}, function (response) { - currentCompletionKeys = response.completionKeys; - }); +// TODO(ilya): This just checks if "google" is in the domain name. Probably should be more targeted. +function isGoogleSearch() { + var url = window.location.toString(); + return !!url.match(googleRegex); +} + +function refreshCompletionKeys(response) { + if (response) { + currentCompletionKeys = response.completionKeys; + + if (response.validFirstKeys) + validFirstKeys = response.validFirstKeys; + } else { + chrome.extension.sendRequest({ handler: "getCompletionKeys" }, refreshCompletionKeys); + } } function onFocusCapturePhase(event) { |
