aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMurphy McMahon2011-07-14 09:35:14 -0300
committerMurphy McMahon2011-07-14 09:35:14 -0300
commit6ccdb189c575e5f1c539e7fed9f39d2f683b16d4 (patch)
tree123a912e36fac9d97937fd9f5a5e8f1d0c39cafc
parent24bb9827ebb86fe8b59d2959aa1dd40f98657049 (diff)
downloadvimium-6ccdb189c575e5f1c539e7fed9f39d2f683b16d4.tar.bz2
Added clipboard copying to linkHints mode (default binding: 'Y')
-rw-r--r--background_page.html9
-rw-r--r--commands.js5
-rw-r--r--linkHints.js32
-rw-r--r--vimiumFrontend.js5
4 files changed, 41 insertions, 10 deletions
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..7005626b 100644
--- a/commands.js
+++ b/commands.js
@@ -129,6 +129,7 @@ function clearKeyMappingsAndSetDefaults() {
"]]": "goNext",
"yy": "copyCurrentUrl",
+ "Y": "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..75b0fe53 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,10 @@ var linkHints = {
that.delayMode = false;
that.activateModeWithQueue();
});
+ } else if (this.shouldCopyLinkUrl) {
+ console.log(matchedLink);
+ this.copyLinkUrl(matchedLink);
+ this.deactivateMode(delay, function() { that.delayMode = false; });
} else if (this.shouldOpenInNewTab) {
this.simulateClick(matchedLink);
matchedLink.focus();
@@ -250,6 +260,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.
diff --git a/vimiumFrontend.js b/vimiumFrontend.js
index f7ebedfa..2351ebdb 100644
--- a/vimiumFrontend.js
+++ b/vimiumFrontend.js
@@ -336,6 +336,11 @@ function copyCurrentUrl() {
HUD.showForDuration("Yanked URL", 1000);
}
+//function copyLinkUrl(url) {
+ //chrome.extension.sendRequest({ handler: "copyToClipboard", data: url });
+ //HUD.showForDuration("Yanked link URL", 1000);
+//}
+
function toggleViewSourceCallback(url) {
if (url.substr(0, 12) == "view-source:")
{