From 405e487a7347181f6f49f01839c807c84fc93e41 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Fri, 31 Mar 2017 21:48:10 -0700 Subject: ctrl + c to copy --- ext/fg/js/display-frame.js | 27 +++++++++++++++++++++++++++ ext/fg/js/driver.js | 4 ++++ ext/manifest.json | 3 ++- ext/mixed/js/display.js | 3 +++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/ext/fg/js/display-frame.js b/ext/fg/js/display-frame.js index 59032d0c..f6f7683e 100644 --- a/ext/fg/js/display-frame.js +++ b/ext/fg/js/display-frame.js @@ -51,6 +51,10 @@ window.displayFrame = new class extends Display { window.parent.postMessage('popupClose', '*'); } + selectionCopy() { + window.parent.postMessage('selectionCopy', '*'); + } + showOrphaned() { $('#content').hide(); $('#orphan').show(); @@ -77,4 +81,27 @@ window.displayFrame = new class extends Display { handler(params); } } + + onKeyDown(e) { + if (super.onKeyDown(e)) { + return true; + } + + const handlers = { + 67: /* c */ () => { + if (e.ctrlKey) { + this.selectionCopy(); + return true; + } + } + }; + + const handler = handlers[e.keyCode]; + if (handler && handler()) { + e.preventDefault(); + return true; + } + + return false; + } }; diff --git a/ext/fg/js/driver.js b/ext/fg/js/driver.js index 5191f18d..d4cb1532 100644 --- a/ext/fg/js/driver.js +++ b/ext/fg/js/driver.js @@ -106,6 +106,10 @@ window.driver = new class { const handlers = { popupClose: () => { this.searchClear(); + }, + + selectionCopy: () => { + document.execCommand('copy'); } }; diff --git a/ext/manifest.json b/ext/manifest.json index 83df26e4..3939ae21 100644 --- a/ext/manifest.json +++ b/ext/manifest.json @@ -29,7 +29,8 @@ }, "permissions": [ "", - "storage" + "storage", + "clipboardWrite" ], "commands": { "toggle": { diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 9738319a..f950f0f0 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -301,7 +301,10 @@ class Display { const handler = handlers[e.keyCode]; if (handler && handler()) { e.preventDefault(); + return true; } + + return false; } sourceBack() { -- cgit v1.2.3