diff options
| author | Ilya | 2011-07-15 10:39:54 -0700 | 
|---|---|---|
| committer | Ilya | 2011-07-15 10:39:54 -0700 | 
| commit | 4d3c49d662d6e2674e2090d24adffd89745fc990 (patch) | |
| tree | 4b0132b2bbf78fabac82372f5f0511e5a3673c0e | |
| parent | 24bb9827ebb86fe8b59d2959aa1dd40f98657049 (diff) | |
| parent | d66e1e85243ce5da548bf7027c96fa45cfb6f364 (diff) | |
| download | vimium-4d3c49d662d6e2674e2090d24adffd89745fc990.tar.bz2 | |
Merge pull request #372 from pandeiro/master
Add link-copying functionality to linkHints mode
| -rw-r--r-- | CREDITS | 1 | ||||
| -rw-r--r-- | README.markdown | 1 | ||||
| -rw-r--r-- | background_page.html | 9 | ||||
| -rw-r--r-- | commands.js | 5 | ||||
| -rw-r--r-- | linkHints.js | 31 | 
5 files changed, 37 insertions, 10 deletions
@@ -18,6 +18,7 @@ Contributors:    lack    markstos    Matthew Cline <matt@nightrealms.com> +  Murph (github: pandeiro)    rodimius    Tim Morgan <tim@timmorgan.org> (github: seven1m)    tsigo diff --git a/README.markdown b/README.markdown index 19fc7b96..124ccaad 100644 --- a/README.markdown +++ b/README.markdown @@ -44,6 +44,7 @@ Navigating the current page:      zo      zoom out      i       enter insert mode -- all commands will be ignored until you hit esc to exit      yy      copy the current url to the clipboard +    yf      copy a link url to the clipboard      gf      cycle forward to the next frame  Using find: diff --git a/background_page.html b/background_page.html index 71bbcf7a..5de86bca 100644 --- a/background_page.html +++ b/background_page.html @@ -81,6 +81,7 @@      upgradeNotificationClosed: upgradeNotificationClosed,      updateScrollPosition: handleUpdateScrollPosition,      copyToClipboard: copyToClipboard, +    copyLinkUrl: copyLinkUrl,      isEnabledForUrl: isEnabledForUrl,      saveHelpDialogSettings: saveHelpDialogSettings    }; @@ -261,6 +262,14 @@        chrome.tabs.create({ url: request.url, index: tab.index + 1, selected: request.selected });      });    } + +  /** +   * Copies url of selected link to the clipboard (wget ftw) +   */ +  function copyLinkUrl(request) { +    Clipboard.copy(request.data); +  } +    /*     * Returns the core CSS used for link hints, along with any user-provided overrides.     */ diff --git a/commands.js b/commands.js index 8e642665..4e7ebccb 100644 --- a/commands.js +++ b/commands.js @@ -129,6 +129,7 @@ function clearKeyMappingsAndSetDefaults() {      "]]": "goNext",      "yy": "copyCurrentUrl", +    "yf": "linkHints.activateModeToCopyLinkUrl",      "K": "nextTab",      "J": "previousTab", @@ -173,6 +174,8 @@ var commandDescriptions = {    zoomOut: ["Zoom out"],    zoomReset: ["Reset zoom to default value"],    copyCurrentUrl: ["Copy the current URL to the clipboard"], +   +  'linkHints.activateModeToCopyLinkUrl': ["Copy a link URL to the clipboard"],    enterInsertMode: ["Enter insert mode"], @@ -220,7 +223,7 @@ var commandGroups = {      ["scrollDown", "scrollUp", "scrollLeft", "scrollRight",       "scrollToTop", "scrollToBottom", "scrollToLeft", "scrollToRight", "scrollPageDown",       "scrollPageUp", "scrollFullPageUp", "scrollFullPageDown", -     "reload", "toggleViewSource", "zoomIn", "zoomOut", "zoomReset", "copyCurrentUrl", "goUp", +     "reload", "toggleViewSource", "zoomIn", "zoomOut", "zoomReset", "copyCurrentUrl", "linkHints.activateModeToCopyLinkUrl", "goUp",       "enterInsertMode", "focusInput",       "linkHints.activateMode", "linkHints.activateModeToOpenInNewTab", "linkHints.activateModeWithQueue",       "activateBookmarkFindMode", "activateBookmarkFindModeToOpenInNewTab", diff --git a/linkHints.js b/linkHints.js index 9219fee6..e3ecacfb 100644 --- a/linkHints.js +++ b/linkHints.js @@ -8,13 +8,14 @@   * In 'filter' mode, our link hints are numbers, and the user can narrow down the range of possibilities by   * typing the text of the link itself.   */ -  var linkHints = {    hintMarkers: [],    hintMarkerContainingDiv: null,    // The characters that were typed in while in "link hints" mode.    shouldOpenInNewTab: false,    shouldOpenWithQueue: false, +  // flag for copying link instead of opening +  shouldCopyLinkUrl: false,    // Whether link hint's "open in current/new tab" setting is currently toggled     openLinkModeToggle: false,    // Whether we have added to the page the CSS needed to display link hints. @@ -48,15 +49,17 @@ var linkHints = {    })(),    // We need this as a top-level function because our command system doesn't yet support arguments. -  activateModeToOpenInNewTab: function() { this.activateMode(true, false); }, +  activateModeToOpenInNewTab: function() { this.activateMode(true, false, false); }, + +  activateModeToCopyLinkUrl: function() { this.activateMode(false, false, true); }, -  activateModeWithQueue: function() { this.activateMode(true, true); }, +  activateModeWithQueue: function() { this.activateMode(true, true, false); }, -  activateMode: function(openInNewTab, withQueue) { +  activateMode: function(openInNewTab, withQueue, copyLinkUrl) {      if (!this.cssAdded)        addCssToPage(linkHintCss); // linkHintCss is declared by vimiumFrontend.js      this.linkHintCssAdded = true; -    this.setOpenLinkMode(openInNewTab, withQueue); +    this.setOpenLinkMode(openInNewTab, withQueue, copyLinkUrl);      this.buildLinkHints();      handlerStack.push({ // modeKeyHandler is declared by vimiumFrontend.js        keydown: this.onKeyDownInMode, @@ -64,10 +67,13 @@ var linkHints = {      });    }, -  setOpenLinkMode: function(openInNewTab, withQueue) { +  setOpenLinkMode: function(openInNewTab, withQueue, copyLinkUrl) {      this.shouldOpenInNewTab = openInNewTab;      this.shouldOpenWithQueue = withQueue; -    if (this.shouldOpenWithQueue) { +    this.shouldCopyLinkUrl = copyLinkUrl; +    if (this.shouldCopyLinkUrl) { +      HUD.show("Copy link URL to Clipboard"); +    } else if (this.shouldOpenWithQueue) {        HUD.show("Open multiple links in a new tab");      } else {        if (this.shouldOpenInNewTab) @@ -174,7 +180,7 @@ var linkHints = {      if (event.keyCode == keyCodes.shiftKey && !this.openLinkModeToggle) {        // Toggle whether to open link in a new or current tab. -      this.setOpenLinkMode(!this.shouldOpenInNewTab, this.shouldOpenWithQueue); +      this.setOpenLinkMode(!this.shouldOpenInNewTab, this.shouldOpenWithQueue, false);        this.openLinkModeToggle = true;      } @@ -204,7 +210,7 @@ var linkHints = {    onKeyUpInMode: function(event) {      if (event.keyCode == keyCodes.shiftKey && this.openLinkModeToggle) {        // Revert toggle on whether to open link in new or current tab.  -      this.setOpenLinkMode(!this.shouldOpenInNewTab, this.shouldOpenWithQueue); +      this.setOpenLinkMode(!this.shouldOpenInNewTab, this.shouldOpenWithQueue, false);        this.openLinkModeToggle = false;      }      event.stopPropagation(); @@ -227,6 +233,9 @@ var linkHints = {            that.delayMode = false;            that.activateModeWithQueue();          }); +      } else if (this.shouldCopyLinkUrl) { +        this.copyLinkUrl(matchedLink); +        this.deactivateMode(delay, function() { that.delayMode = false; });        } else if (this.shouldOpenInNewTab) {          this.simulateClick(matchedLink);          matchedLink.focus(); @@ -250,6 +259,10 @@ var linkHints = {          element.nodeName.toLowerCase() == "textarea";    }, +  copyLinkUrl: function(link) { +    chrome.extension.sendRequest({handler: 'copyLinkUrl', data: link.href}); +  }, +    simulateSelect: function(element) {      element.focus();      // When focusing a textbox, put the selection caret at the end of the textbox's contents.  | 
