From c76cc33ebfc4e501e0322c3d70ca88770c70bbc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Mon, 22 Feb 2021 13:23:39 +0100 Subject: [PATCH] Don't show copy button if there is no MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/components/views/messages/TextualBody.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/views/messages/TextualBody.js b/src/components/views/messages/TextualBody.js index 6b201f1b8e..632e2e4afe 100644 --- a/src/components/views/messages/TextualBody.js +++ b/src/components/views/messages/TextualBody.js @@ -161,6 +161,9 @@ export default class TextualBody extends React.Component { } _addCodeCopyButton(div) { + const copyCode = div.getElementsByTagName("code")[0]; + // If there isn't any code element don't show the copy button + if (!copyCode) return; const button = document.createElement("span"); button.className = "mx_EventTile_button mx_EventTile_copyButton "; @@ -170,7 +173,6 @@ export default class TextualBody extends React.Component { if (expansionButtonExists.length > 0) button.className += "mx_EventTile_buttonBottom"; button.onclick = async () => { - const copyCode = button.parentNode.getElementsByTagName("code")[0]; const successful = await copyPlaintext(copyCode.textContent); const buttonRect = button.getBoundingClientRect();