From 2d50a8aa956e8eccb104d6875afe4d55f05281fe Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sun, 15 Aug 2021 01:15:39 -0400 Subject: [PATCH] ace2_inner: Fix efficiency of `rangeForLine()` Returning `true` or `false` has no effect when iterating using `Array.prototype.forEach`. This fixes a bug introduced in commit b28bfe8e31cf4a95b1242bc35b47201f7560a0a3. --- src/static/js/ace2_inner.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index 1487349b1..5f1885969 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -2162,16 +2162,13 @@ function Ace2Inner(editorInfo, cssManagers) { [-1, N + 1], ]; + // returns index of cleanRange containing i, or -1 if none const rangeForLine = (i) => { - // returns index of cleanRange containing i, or -1 if none - let answer = -1; - cleanRanges.forEach((r, idx) => { - if (i >= r[1]) return false; // keep looking - if (i < r[0]) return true; // not found, stop looking - answer = idx; - return true; // found, stop looking - }); - return answer; + for (const [idx, r] of cleanRanges.entries()) { + if (i < r[0]) return -1; + if (i < r[1]) return idx; + } + return -1; }; const removeLineFromRange = (rng, line) => {