diff --git a/src/core/components/highlight-code.jsx b/src/core/components/highlight-code.jsx index 465a0cd6ee8..982179944e7 100644 --- a/src/core/components/highlight-code.jsx +++ b/src/core/components/highlight-code.jsx @@ -16,17 +16,26 @@ export default class HighlightCode extends Component { canCopy: PropTypes.bool } - #syntaxHighlighter; - #pre; + #childNodes downloadText = () => { saveAs(this.props.value, this.props.fileName || "response.txt") } + handleRootRef = (node) => { + if (node === null) { + this.#childNodes = node + } else { + this.#childNodes = Array + .from(node.childNodes) + .filter(node => !!node.nodeType && node.classList.contains("microlight")) + } + } + preventYScrollingBeyondElement = (e) => { const target = e.target - var deltaY = e.nativeEvent.deltaY + var deltaY = e.deltaY var contentHeight = target.scrollHeight var visibleHeight = target.offsetHeight var scrollTop = target.scrollTop @@ -43,13 +52,11 @@ export default class HighlightCode extends Component { } componentDidMount() { - [this.#syntaxHighlighter, this.#pre] - .map(element => element?.addEventListener("mousewheel", this.preventYScrollingBeyondElement, { passive: false })) + this.#childNodes?.forEach(node => node.addEventListener("mousewheel", this.preventYScrollingBeyondElement, { passive: false })) } componentWillUnmount() { - [this.#syntaxHighlighter, this.#pre] - .map(element => element?.removeEventListener("mousewheel", this.preventYScrollingBeyondElement)) + this.#childNodes?.forEach(node => node.removeEventListener("mousewheel", this.preventYScrollingBeyondElement)) } render () { @@ -61,17 +68,16 @@ export default class HighlightCode extends Component { const codeBlock = get(config, "syntaxHighlight.activated") ? this.#syntaxHighlighter = elem} language={language} className={className + " microlight"} style={getStyle(get(config, "syntaxHighlight.theme"))} > {value} - :
 this.#pre = elem} className={className + " microlight"}>{value}
+ :
{value}
return ( -
+
{ !downloadable ? null :
Download