This somehow works

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
Šimon Brandner 2021-01-19 21:02:39 +01:00
parent 95939f3d6c
commit 58b2c18cf5
No known key found for this signature in database
GPG key ID: 9760693FDD98A790
6 changed files with 124 additions and 4 deletions

View file

@ -97,8 +97,9 @@ export default class TextualBody extends React.Component {
// Wrap a div around <pre> so that the copy button can be correctly positioned
// when the <pre> overflows and is scrolled horizontally.
const div = this._wrapInDiv(blocks[i]);
this._handleCodeBlockExpansion(div);
this._handleCodeBlockExpansion(div.firstChild);
this._addCodeCopyButton(div);
this._addCodeExpansionButton(div);
}
// Do this asynchronously: parsing code takes time and we don't
// need to block the DOM update on it.
@ -112,6 +113,30 @@ export default class TextualBody extends React.Component {
}
}
_addCodeExpansionButton(codeBlock) {
// TODO: What if the block is small and the we don't need the icon?
const pre = codeBlock.getElementsByTagName("pre")[0];
const button = document.createElement("span");
if (pre.className == "mx_EventTile_collapsedCodeBlock") {
button.className = "mx_EventTile_expandButton";
} else {
button.className = "mx_EventTile_collapseButton";
}
button.onclick = async () => {
if (pre.className == "mx_EventTile_collapsedCodeBlock") {
pre.className = "";
button.className = "mx_EventTile_expandButton";
} else {
pre.className = "mx_EventTile_collapsedCodeBlock";
button.className = "mx_EventTile_collapseButton";
}
};
codeBlock.appendChild(button);
}
_addCodeCopyButton(codeBlock) {
const button = document.createElement("span");
button.className = "mx_EventTile_copyButton";