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 theoverflows 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 aroundso that the copy button can be correctly positioned - // when theoverflows 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 ofblock codeBlock.parentNode.replaceChild(div, codeBlock); - // Appendblock and copy button to container div.appendChild(codeBlock); - div.appendChild(button); + + return div; } _handleCodeBlockExpansion(codeBlock) {