From 9fda5adcefd86bfaba267d4988954bbe54ddd6c2 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Thu, 29 Jul 2021 01:22:44 -0400 Subject: [PATCH] ace2_inner.js: Improve discovery of `sidediv` and `linemetricsdiv` The `Node.nextSibling` property returns the next Node, not the next Element. If whitespace, an HTML comment, or any other type of non-Element Node is ever introduced between the Elements then `.nextSibling` no longer returns the desired Element. Switching to `Element.nextElementSibling` would work, but finding the Elements by ID is more readable and future-proof. --- src/static/js/ace2_inner.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index caed956c2..32fc0a84f 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -60,10 +60,10 @@ function Ace2Inner(editorInfo, cssManagers) { window.focus(); }; - const iframe = window.frameElement; const outerWin = window.parent; - const sideDiv = iframe.nextSibling; - const lineMetricsDiv = sideDiv.nextSibling; + const outerDoc = outerWin.document; + const sideDiv = outerDoc.getElementById('sidediv'); + const lineMetricsDiv = outerDoc.getElementById('linemetricsdiv'); let lineNumbersShown; let sideDivInner;