summaryrefslogtreecommitdiff
path: root/ext/fg/js/float.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-11-14 21:47:43 -0500
committerGitHub <noreply@github.com>2020-11-14 21:47:43 -0500
commitc387898902cf24e017e18f9e3bb140df5d791bb7 (patch)
tree88c5aaabd59ab168095362dc9a8da43200746efb /ext/fg/js/float.js
parent4b1c7b1e269b98eaf4906c82cb3fd09566dce7be (diff)
Display fixes (#1033)
* Fix an entry not always being focused * Fix typo * Fix copy action not working on Firefox
Diffstat (limited to 'ext/fg/js/float.js')
-rw-r--r--ext/fg/js/float.js44
1 files changed, 43 insertions, 1 deletions
diff --git a/ext/fg/js/float.js b/ext/fg/js/float.js
index 3b752df5..9f58439f 100644
--- a/ext/fg/js/float.js
+++ b/ext/fg/js/float.js
@@ -29,6 +29,8 @@ class DisplayFloat extends Display {
this._windowMessageHandlers = new Map([
['extensionUnloaded', {async: false, handler: this._onMessageExtensionUnloaded.bind(this)}]
]);
+ this._browser = null;
+ this._copyTextarea = null;
this.registerActions([
['copyHostSelection', () => this._copySelection()]
@@ -43,6 +45,9 @@ class DisplayFloat extends Display {
async prepare() {
await super.prepare();
+ const {browser} = await api.getEnvironmentInfo();
+ this._browser = browser;
+
this.registerDirectMessageHandlers([
['configure', {async: true, handler: this._onMessageConfigure.bind(this)}],
['setContentScale', {async: false, handler: this._onMessageSetContentScale.bind(this)}]
@@ -150,10 +155,47 @@ class DisplayFloat extends Display {
_copySelection() {
if (window.getSelection().toString()) { return false; }
- this._invokeOwner('copySelection');
+ this._copyHostSelection();
return true;
}
+ async _copyHostSelection() {
+ switch (this._browser) {
+ case 'firefox':
+ case 'firefox-mobile':
+ {
+ let text;
+ try {
+ text = await this._invokeOwner('getSelectionText');
+ } catch (e) {
+ break;
+ }
+ this._copyText(text);
+ }
+ break;
+ default:
+ this._invokeOwner('copySelection');
+ break;
+ }
+ }
+
+ _copyText(text) {
+ const parent = document.body;
+ if (parent === null) { return; }
+
+ let textarea = this._copyTextarea;
+ if (textarea === null) {
+ textarea = document.createElement('textarea');
+ this._copyTextarea = textarea;
+ }
+
+ textarea.value = text;
+ parent.appendChild(textarea);
+ textarea.select();
+ document.execCommand('copy');
+ parent.removeChild(textarea);
+ }
+
_setContentScale(scale) {
const body = document.body;
if (body === null) { return; }