Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Use keydown for copy to clipboard b/c MacOS. (#3879)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenba committed Dec 9, 2017
1 parent 3671146 commit 9f1da5a
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions addon/webextension/selector/uicontrol.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,12 @@ this.uicontrol = (function() {
watchPromise(ui.iframe.display(installHandlersOnDocument, standardOverlayCallbacks).then(() => {
ui.iframe.usePreSelection();
ui.Box.remove();
const handler = watchFunction(assertIsTrusted(keyupHandler));
document.addEventListener("keyup", handler);
registeredDocumentHandlers.push({name: "keyup", doc: document, handler, useCapture: false});
const upHandler = watchFunction(assertIsTrusted(keyupHandler));
document.addEventListener("keyup", upHandler);
registeredDocumentHandlers.push({name: "keyup", doc: document, upHandler, useCapture: false});
const downHandler = watchFunction(assertIsTrusted(keydownHandler));
document.addEventListener("keydown", downHandler);
registeredDocumentHandlers.push({name: "keydown", doc: document, downHandler, useCapture: false});
}));
},

Expand Down Expand Up @@ -946,6 +949,7 @@ this.uicontrol = (function() {
primedDocumentHandlers.set(eventName, fn);
});
primedDocumentHandlers.set("keyup", watchFunction(assertIsTrusted(keyupHandler)));
primedDocumentHandlers.set("keydown", watchFunction(assertIsTrusted(keydownHandler)));
window.addEventListener('beforeunload', beforeunloadHandler);
}

Expand All @@ -971,11 +975,8 @@ this.uicontrol = (function() {
exports.deactivate();
}

function keyupHandler(event) {
if (event.shiftKey || event.altKey) {
// unused modifier keys
return;
}
function keydownHandler(event) {
// In MacOS, the keyup event for 'c' is not fired when performing cmd+c.
if (event.code === "KeyC" && (event.ctrlKey || event.metaKey)) {
callBackground("getPlatformOs").then(os => {
if ((event.ctrlKey && os !== "mac") ||
Expand All @@ -987,6 +988,13 @@ this.uicontrol = (function() {
// handled by catcher.watchPromise
});
}
}

function keyupHandler(event) {
if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) {
// unused modifier keys
return;
}
if ((event.key || event.code) === "Escape") {
sendEvent("cancel-shot", "keyboard-escape");
exports.deactivate();
Expand Down

0 comments on commit 9f1da5a

Please sign in to comment.