From a1def2f146763a11bed6a787bff90327d313c54f Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke <marijnh@gmail.com> Date: Tue, 19 Jul 2011 15:04:35 +0200 Subject: [PATCH] Cache max line pixel width --- lib/codemirror.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/codemirror.js b/lib/codemirror.js index 82405ff4..7a0919aa 100644 --- a/lib/codemirror.js +++ b/lib/codemirror.js @@ -72,7 +72,7 @@ var CodeMirror = (function() { var editing, bracketHighlighted; // Tracks the maximum line length so that the horizontal scrollbar // can be kept static when scrolling. - var maxLine = ""; + var maxLine = "", maxWidth; // Initialize the content. operation(function(){setValue(options.value || ""); updateInput = false;})(); @@ -463,12 +463,12 @@ var CodeMirror = (function() { for (var i = from.line, e = i + newText.length; i < e; ++i) { var l = lines[i].text; if (l.length > maxLineLength) { - maxLine = l; maxLineLength = l.length; + maxLine = l; maxLineLength = l.length; maxWidth = null; recomputeMaxLength = false; } } if (recomputeMaxLength) { - maxLineLength = 0; maxLine = ""; + maxLineLength = 0; maxLine = ""; maxWidth = null; for (var i = 0, e = lines.length; i < e; ++i) { var l = lines[i].text; if (l.length > maxLineLength) { @@ -769,9 +769,9 @@ var CodeMirror = (function() { updateGutter(); } - var textWidth = stringWidth(maxLine); - if (textWidth > scroller.clientWidth) { - lineSpace.style.width = textWidth + "px"; + if (maxWidth == null) maxWidth = stringWidth(maxLine); + if (maxWidth > scroller.clientWidth) { + lineSpace.style.width = maxWidth + "px"; // Needed to prevent odd wrapping/hiding of widgets placed in here. code.style.width = scroller.scrollWidth + "px"; } else { -- GitLab