From 95939f3d6ca34c1757903f1efa28aeca4c911fd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Tue, 19 Jan 2021 18:21:59 +0100 Subject: [PATCH] Added _wrapInDiv() method 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 | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/components/views/messages/TextualBody.js b/src/components/views/messages/TextualBody.js index 84a21c0da3..a6b32baea2 100644 --- a/src/components/views/messages/TextualBody.js +++ b/src/components/views/messages/TextualBody.js @@ -94,8 +94,11 @@ export default class TextualBody extends React.Component { const blocks = ReactDOM.findDOMNode(this).getElementsByTagName("pre"); if (blocks.length > 0) { for (let i = 0; i < blocks.length; i++) { - this._handleCodeBlockExpansion(blocks[i]); - this._addCodeCopyButton(blocks[i]); + // Wrap a div around
 so that the copy button can be correctly positioned
+                    // when the 
 overflows and is scrolled horizontally.
+                    const div = this._wrapInDiv(blocks[i]);
+                    this._handleCodeBlockExpansion(div);
+                    this._addCodeCopyButton(div);
                 }
                 // Do this asynchronously: parsing code takes time and we don't
                 // need to block the DOM update on it.
@@ -125,17 +128,19 @@ export default class TextualBody extends React.Component {
             button.onmouseleave = close;
         };
 
-        // Wrap a div around 
 so that the copy button can be correctly positioned
-        // when the 
 overflows and is scrolled horizontally.
+        codeBlock.appendChild(button);
+    }
+
+    _wrapInDiv(codeBlock) {
         const div = document.createElement("div");
         div.className = "mx_EventTile_pre_container";
 
         // Insert containing div in place of 
 block
         codeBlock.parentNode.replaceChild(div, codeBlock);
-
         // Append 
 block and copy button to container
         div.appendChild(codeBlock);
-        div.appendChild(button);
+
+        return div;
     }
 
     _handleCodeBlockExpansion(codeBlock) {