Skip to content
This repository
Browse code

Add maxHighlightLength option

  • Loading branch information...
commit ca79fa2066b956bc290abfcee2be6224cbed9a5b 1 parent 1b150c9
Marijn Haverbeke authored March 27, 2013
7  doc/manual.html
@@ -326,6 +326,13 @@ <h2 id="config">Configuration</h2>
326 326
       document looks. You can set this option to false to disable this
327 327
       behavior.</dd>
328 328
 
  329
+      <dt id="option_maxHighlightLength"><code>maxHighlightLength (number)</code></dt>
  330
+      <dd>When highlighting long lines, in order to stay responsive,
  331
+      the editor will give up and simply style the rest of the line as
  332
+      plain text when it reaches a certain position. The default is
  333
+      10000. You can set this to <code>Infinity</code> to turn off
  334
+      this behavior.</dd>
  335
+
329 336
       <dt id="option_viewportMargin"><code>viewportMargin (integer)</code></dt>
330 337
       <dd>Specifies the amount of lines that are rendered above and
331 338
       below the part of the document that's currently scrolled into
10  lib/codemirror.js
@@ -3087,6 +3087,7 @@ window.CodeMirror = (function() {
3087 3087
   option("pollInterval", 100);
3088 3088
   option("undoDepth", 40, function(cm, val){cm.doc.history.undoDepth = val;});
3089 3089
   option("viewportMargin", 10, function(cm){cm.refresh();}, true);
  3090
+  option("maxHighlightLength", 10000, function(cm){loadMode(cm); cm.refresh();}, true);
3090 3091
 
3091 3092
   option("tabindex", null, function(cm, val) {
3092 3093
     cm.display.input.tabIndex = val || "";
@@ -3978,15 +3979,16 @@ window.CodeMirror = (function() {
3978 3979
     var flattenSpans = mode.flattenSpans;
3979 3980
     if (flattenSpans == null) flattenSpans = cm.options.flattenSpans;
3980 3981
     var curText = "", curStyle = null;
3981  
-    var stream = new StringStream(text, cm.options.tabSize);
  3982
+    var stream = new StringStream(text, cm.options.tabSize), style;
3982 3983
     if (text == "" && mode.blankLine) mode.blankLine(state);
3983 3984
     while (!stream.eol()) {
3984  
-      var style = mode.token(stream, state);
3985  
-      if (stream.pos > 5000) {
  3985
+      if (stream.pos > cm.options.maxHighlightLength) {
3986 3986
         flattenSpans = false;
3987 3987
         // Webkit seems to refuse to render text nodes longer than 57444 characters
3988 3988
         stream.pos = Math.min(text.length, stream.start + 50000);
3989 3989
         style = null;
  3990
+      } else {
  3991
+        style = mode.token(stream, state);
3990 3992
       }
3991 3993
       var substr = stream.current();
3992 3994
       stream.start = stream.pos;
@@ -4049,7 +4051,7 @@ window.CodeMirror = (function() {
4049 4051
     var mode = cm.doc.mode;
4050 4052
     var stream = new StringStream(line.text, cm.options.tabSize);
4051 4053
     if (line.text == "" && mode.blankLine) mode.blankLine(state);
4052  
-    while (!stream.eol() && stream.pos <= 5000) {
  4054
+    while (!stream.eol() && stream.pos <= cm.options.maxHighlightLength) {
4053 4055
       mode.token(stream, state);
4054 4056
       stream.start = stream.pos;
4055 4057
     }

0 notes on commit ca79fa2

Please sign in to comment.
Something went wrong with that request. Please try again.