From 09defc66fe78f0c95d8415534a7906d9318ab121 Mon Sep 17 00:00:00 2001 From: dashwav Date: Thu, 19 Dec 2019 21:21:53 -0700 Subject: [PATCH] Add Copy Message Contents option in Context Menu Uglier solution, but has much wider support including Safari+SafariIOS Remove unused code --- .../views/context_menus/MessageContextMenu.js | 20 +++++++++++++++++++ src/i18n/strings/en_US.json | 3 ++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/components/views/context_menus/MessageContextMenu.js b/src/components/views/context_menus/MessageContextMenu.js index efbfc4322f5..8128c2c663e 100644 --- a/src/components/views/context_menus/MessageContextMenu.js +++ b/src/components/views/context_menus/MessageContextMenu.js @@ -253,6 +253,16 @@ module.exports = createReactClass({ this.closeMenu(); }, + onCopyClick: function(e: Event) { + const textField = document.createElement('textarea'); + textField.innerText = this.props.mxEvent.event.content.body; + document.body.appendChild(textField); + textField.select(); + document.execCommand('copy'); + textField.remove(); + this.closeMenu(); + }, + onPermalinkClick: function(e: Event) { e.preventDefault(); const ShareDialog = sdk.getComponent("dialogs.ShareDialog"); @@ -314,6 +324,7 @@ module.exports = createReactClass({ let unhidePreviewButton; let externalURLButton; let quoteButton; + let copyButton; let collapseReplyThread; // status is SENT before remote-echo, null after @@ -430,6 +441,14 @@ module.exports = createReactClass({ ); } + if (this.props.eventTileOps && this.props.eventTileOps.getInnerText) { + copyButton = ( + + { _t('Copy Message Contents') } + + ); + } + // Bridges can provide a 'external_url' to link back to the source. if ( typeof(mxEvent.event.content.external_url) === "string" && @@ -491,6 +510,7 @@ module.exports = createReactClass({ { unhidePreviewButton } { permalinkButton } { quoteButton } + { copyButton } { externalURLButton } { collapseReplyThread } { e2eInfo } diff --git a/src/i18n/strings/en_US.json b/src/i18n/strings/en_US.json index 70e4bf5092a..bece808b14f 100644 --- a/src/i18n/strings/en_US.json +++ b/src/i18n/strings/en_US.json @@ -746,5 +746,6 @@ "Failed to start chat": "Failed to start chat", "Messages": "Messages", "Actions": "Actions", - "Other": "Other" + "Other": "Other", + "Copy Message Contents": "Copy Message Contents" }