codemirror-rails 3.02 → 3.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +1 -1
  3. data/LICENSE +1 -1
  4. data/codemirror-rails.gemspec +1 -0
  5. data/doc/CodeMirror-LICENSE +5 -1
  6. data/lib/codemirror/rails/version.rb +2 -2
  7. data/vendor/assets/javascripts/codemirror/{utils → addons/dialog}/dialog.js +4 -0
  8. data/vendor/assets/javascripts/codemirror/addons/display/placeholder.js +54 -0
  9. data/vendor/assets/javascripts/codemirror/addons/edit/closebrackets.js +54 -0
  10. data/vendor/assets/javascripts/codemirror/{utils → addons/edit}/closetag.js +9 -8
  11. data/vendor/assets/javascripts/codemirror/{utils → addons/edit}/continuecomment.js +12 -4
  12. data/vendor/assets/javascripts/codemirror/addons/edit/continuelist.js +25 -0
  13. data/vendor/assets/javascripts/codemirror/{utils → addons/edit}/matchbrackets.js +30 -11
  14. data/vendor/assets/javascripts/codemirror/addons/fold/brace-fold.js +31 -0
  15. data/vendor/assets/javascripts/codemirror/addons/fold/foldcode.js +32 -0
  16. data/vendor/assets/javascripts/codemirror/addons/fold/indent-fold.js +11 -0
  17. data/vendor/assets/javascripts/codemirror/addons/fold/xml-fold.js +64 -0
  18. data/vendor/assets/javascripts/codemirror/addons/hint/html-hint.js +582 -0
  19. data/vendor/assets/javascripts/codemirror/{utils → addons/hint}/javascript-hint.js +15 -11
  20. data/vendor/assets/javascripts/codemirror/{utils → addons/hint}/pig-hint.js +19 -19
  21. data/vendor/assets/javascripts/codemirror/{utils → addons/hint}/python-hint.js +2 -2
  22. data/vendor/assets/javascripts/codemirror/addons/hint/show-hint.js +180 -0
  23. data/vendor/assets/javascripts/codemirror/{utils → addons/hint}/xml-hint.js +5 -18
  24. data/vendor/assets/javascripts/codemirror/addons/lint/javascript-lint.js +127 -0
  25. data/vendor/assets/javascripts/codemirror/addons/lint/json-lint.js +14 -0
  26. data/vendor/assets/javascripts/codemirror/addons/lint/lint.js +197 -0
  27. data/vendor/assets/javascripts/codemirror/{utils → addons/mode}/loadmode.js +0 -0
  28. data/vendor/assets/javascripts/codemirror/{utils → addons/mode}/multiplex.js +2 -2
  29. data/vendor/assets/javascripts/codemirror/{utils → addons/mode}/overlay.js +2 -2
  30. data/vendor/assets/javascripts/codemirror/{utils → addons/runmode}/colorize.js +0 -0
  31. data/vendor/assets/javascripts/codemirror/{utils → addons/runmode}/runmode-standalone.js +2 -3
  32. data/vendor/assets/javascripts/codemirror/{utils → addons/runmode}/runmode.js +0 -0
  33. data/vendor/assets/javascripts/codemirror/addons/runmode/runmode.node.js +89 -0
  34. data/vendor/assets/javascripts/codemirror/addons/search/match-highlighter.js +60 -0
  35. data/vendor/assets/javascripts/codemirror/{utils → addons/search}/search.js +5 -5
  36. data/vendor/assets/javascripts/codemirror/{utils → addons/search}/searchcursor.js +37 -30
  37. data/vendor/assets/javascripts/codemirror/addons/selection/active-line.js +39 -0
  38. data/vendor/assets/javascripts/codemirror/addons/selection/mark-selection.js +34 -0
  39. data/vendor/assets/javascripts/codemirror/keymaps/vim.js +721 -188
  40. data/vendor/assets/javascripts/codemirror/modes/asterisk.js +6 -6
  41. data/vendor/assets/javascripts/codemirror/modes/clike.js +14 -14
  42. data/vendor/assets/javascripts/codemirror/modes/clojure.js +23 -7
  43. data/vendor/assets/javascripts/codemirror/modes/coffeescript.js +2 -2
  44. data/vendor/assets/javascripts/codemirror/modes/css.js +337 -235
  45. data/vendor/assets/javascripts/codemirror/modes/ecl.js +12 -12
  46. data/vendor/assets/javascripts/codemirror/modes/erlang.js +1 -1
  47. data/vendor/assets/javascripts/codemirror/modes/gas.js +326 -0
  48. data/vendor/assets/javascripts/codemirror/modes/gfm.js +1 -0
  49. data/vendor/assets/javascripts/codemirror/modes/haskell.js +26 -26
  50. data/vendor/assets/javascripts/codemirror/modes/haxe.js +17 -17
  51. data/vendor/assets/javascripts/codemirror/modes/htmlembedded.js +6 -6
  52. data/vendor/assets/javascripts/codemirror/modes/htmlmixed.js +43 -23
  53. data/vendor/assets/javascripts/codemirror/modes/javascript.js +78 -33
  54. data/vendor/assets/javascripts/codemirror/modes/jinja2.js +2 -2
  55. data/vendor/assets/javascripts/codemirror/modes/less.js +38 -38
  56. data/vendor/assets/javascripts/codemirror/modes/livescript.js +267 -0
  57. data/vendor/assets/javascripts/codemirror/modes/lua.js +7 -7
  58. data/vendor/assets/javascripts/codemirror/modes/markdown.js +108 -57
  59. data/vendor/assets/javascripts/codemirror/modes/mirc.js +177 -0
  60. data/vendor/assets/javascripts/codemirror/modes/ntriples.js +22 -22
  61. data/vendor/assets/javascripts/codemirror/modes/ocaml.js +1 -1
  62. data/vendor/assets/javascripts/codemirror/modes/perl.js +791 -791
  63. data/vendor/assets/javascripts/codemirror/modes/php.js +1 -1
  64. data/vendor/assets/javascripts/codemirror/modes/pig.js +163 -163
  65. data/vendor/assets/javascripts/codemirror/modes/python.js +31 -31
  66. data/vendor/assets/javascripts/codemirror/modes/q.js +124 -0
  67. data/vendor/assets/javascripts/codemirror/modes/rst.js +486 -250
  68. data/vendor/assets/javascripts/codemirror/modes/sass.js +3 -3
  69. data/vendor/assets/javascripts/codemirror/modes/scss_test.js +80 -0
  70. data/vendor/assets/javascripts/codemirror/modes/shell.js +2 -2
  71. data/vendor/assets/javascripts/codemirror/modes/sieve.js +10 -10
  72. data/vendor/assets/javascripts/codemirror/modes/smalltalk.js +129 -129
  73. data/vendor/assets/javascripts/codemirror/modes/smarty.js +3 -3
  74. data/vendor/assets/javascripts/codemirror/modes/sparql.js +1 -1
  75. data/vendor/assets/javascripts/codemirror/modes/sql.js +23 -23
  76. data/vendor/assets/javascripts/codemirror/modes/stex.js +192 -121
  77. data/vendor/assets/javascripts/codemirror/modes/tcl.js +131 -0
  78. data/vendor/assets/javascripts/codemirror/modes/test.js +64 -0
  79. data/vendor/assets/javascripts/codemirror/modes/tiddlywiki.js +345 -345
  80. data/vendor/assets/javascripts/codemirror/modes/tiki.js +297 -298
  81. data/vendor/assets/javascripts/codemirror/modes/turtle.js +145 -0
  82. data/vendor/assets/javascripts/codemirror/modes/vb.js +31 -32
  83. data/vendor/assets/javascripts/codemirror/modes/vbscript.js +4 -4
  84. data/vendor/assets/javascripts/codemirror/modes/xml.js +10 -6
  85. data/vendor/assets/javascripts/codemirror/modes/xquery.js +55 -55
  86. data/vendor/assets/javascripts/codemirror/modes/yaml.js +90 -90
  87. data/vendor/assets/javascripts/codemirror/modes/z80.js +82 -110
  88. data/vendor/assets/javascripts/codemirror.js +1914 -1115
  89. data/vendor/assets/stylesheets/codemirror/{utils → addons/dialog}/dialog.css +0 -0
  90. data/vendor/assets/stylesheets/codemirror/addons/hint/show-hint.css +38 -0
  91. data/vendor/assets/stylesheets/codemirror/addons/lint/lint.css +96 -0
  92. data/vendor/assets/stylesheets/codemirror/modes/tiki.css +2 -2
  93. data/vendor/assets/stylesheets/codemirror/themes/ambiance-mobile.css +0 -1
  94. data/vendor/assets/stylesheets/codemirror/themes/ambiance.css +0 -1
  95. data/vendor/assets/stylesheets/codemirror/themes/eclipse.css +2 -2
  96. data/vendor/assets/stylesheets/codemirror/themes/erlang-dark.css +5 -5
  97. data/vendor/assets/stylesheets/codemirror/themes/midnight.css +52 -0
  98. data/vendor/assets/stylesheets/codemirror/themes/xq-light.css +43 -0
  99. data/vendor/assets/stylesheets/codemirror.css +16 -10
  100. metadata +60 -52
  101. data/vendor/assets/javascripts/codemirror/modes/mysql.js +0 -203
  102. data/vendor/assets/javascripts/codemirror/modes/plsql.js +0 -216
  103. data/vendor/assets/javascripts/codemirror/utils/collapserange.js +0 -68
  104. data/vendor/assets/javascripts/codemirror/utils/continuelist.js +0 -28
  105. data/vendor/assets/javascripts/codemirror/utils/foldcode.js +0 -183
  106. data/vendor/assets/javascripts/codemirror/utils/formatting.js +0 -114
  107. data/vendor/assets/javascripts/codemirror/utils/match-highlighter.js +0 -46
  108. data/vendor/assets/javascripts/codemirror/utils/simple-hint.js +0 -102
  109. data/vendor/assets/stylesheets/codemirror/utils/simple-hint.css +0 -16
@@ -61,7 +61,7 @@ CodeMirror.multiplexingMode = function(outer /*, others */) {
61
61
  return innerToken;
62
62
  }
63
63
  },
64
-
64
+
65
65
  indent: function(state, textAfter) {
66
66
  var mode = state.innerActive ? state.innerActive.mode : outer;
67
67
  if (!mode.indent) return CodeMirror.Pass;
@@ -81,7 +81,7 @@ CodeMirror.multiplexingMode = function(outer /*, others */) {
81
81
  state.inner = CodeMirror.startState(other.mode, mode.indent ? mode.indent(state.outer, "") : 0);
82
82
  }
83
83
  }
84
- } else if (mode.close === "\n") {
84
+ } else if (state.innerActive.close === "\n") {
85
85
  state.innerActive = state.inner = null;
86
86
  }
87
87
  },
@@ -43,14 +43,14 @@ CodeMirror.overlayMode = CodeMirror.overlayParser = function(base, overlay, comb
43
43
  if (state.baseCur != null && combine) return state.baseCur + " " + state.overlayCur;
44
44
  else return state.overlayCur;
45
45
  },
46
-
46
+
47
47
  indent: base.indent && function(state, textAfter) {
48
48
  return base.indent(state.base, textAfter);
49
49
  },
50
50
  electricChars: base.electricChars,
51
51
 
52
52
  innerMode: function(state) { return {state: state.base, mode: base}; },
53
-
53
+
54
54
  blankLine: function(state) {
55
55
  if (base.blankLine) base.blankLine(state.base);
56
56
  if (overlay.blankLine) overlay.blankLine(state.overlay);
@@ -42,13 +42,12 @@ StringStream.prototype = {
42
42
  indentation: function() {return 0;},
43
43
  match: function(pattern, consume, caseInsensitive) {
44
44
  if (typeof pattern == "string") {
45
- function cased(str) {return caseInsensitive ? str.toLowerCase() : str;}
45
+ var cased = function(str) {return caseInsensitive ? str.toLowerCase() : str;};
46
46
  if (cased(this.string).indexOf(cased(pattern), this.pos) == this.pos) {
47
47
  if (consume !== false) this.pos += pattern.length;
48
48
  return true;
49
49
  }
50
- }
51
- else {
50
+ } else {
52
51
  var match = this.string.slice(this.pos).match(pattern);
53
52
  if (match && consume !== false) this.pos += match[0].length;
54
53
  return match;
@@ -0,0 +1,89 @@
1
+ /* Just enough of CodeMirror to run runMode under node.js */
2
+
3
+ function splitLines(string){ return string.split(/\r?\n|\r/); };
4
+
5
+ function StringStream(string) {
6
+ this.pos = this.start = 0;
7
+ this.string = string;
8
+ }
9
+ StringStream.prototype = {
10
+ eol: function() {return this.pos >= this.string.length;},
11
+ sol: function() {return this.pos == 0;},
12
+ peek: function() {return this.string.charAt(this.pos) || null;},
13
+ next: function() {
14
+ if (this.pos < this.string.length)
15
+ return this.string.charAt(this.pos++);
16
+ },
17
+ eat: function(match) {
18
+ var ch = this.string.charAt(this.pos);
19
+ if (typeof match == "string") var ok = ch == match;
20
+ else var ok = ch && (match.test ? match.test(ch) : match(ch));
21
+ if (ok) {++this.pos; return ch;}
22
+ },
23
+ eatWhile: function(match) {
24
+ var start = this.pos;
25
+ while (this.eat(match)){}
26
+ return this.pos > start;
27
+ },
28
+ eatSpace: function() {
29
+ var start = this.pos;
30
+ while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) ++this.pos;
31
+ return this.pos > start;
32
+ },
33
+ skipToEnd: function() {this.pos = this.string.length;},
34
+ skipTo: function(ch) {
35
+ var found = this.string.indexOf(ch, this.pos);
36
+ if (found > -1) {this.pos = found; return true;}
37
+ },
38
+ backUp: function(n) {this.pos -= n;},
39
+ column: function() {return this.start;},
40
+ indentation: function() {return 0;},
41
+ match: function(pattern, consume, caseInsensitive) {
42
+ if (typeof pattern == "string") {
43
+ var cased = function(str) {return caseInsensitive ? str.toLowerCase() : str;};
44
+ if (cased(this.string).indexOf(cased(pattern), this.pos) == this.pos) {
45
+ if (consume !== false) this.pos += pattern.length;
46
+ return true;
47
+ }
48
+ } else {
49
+ var match = this.string.slice(this.pos).match(pattern);
50
+ if (match && consume !== false) this.pos += match[0].length;
51
+ return match;
52
+ }
53
+ },
54
+ current: function(){return this.string.slice(this.start, this.pos);}
55
+ };
56
+ exports.StringStream = StringStream;
57
+
58
+ exports.startState = function(mode, a1, a2) {
59
+ return mode.startState ? mode.startState(a1, a2) : true;
60
+ };
61
+
62
+ var modes = exports.modes = {}, mimeModes = exports.mimeModes = {};
63
+ exports.defineMode = function(name, mode) { modes[name] = mode; };
64
+ exports.defineMIME = function(mime, spec) { mimeModes[mime] = spec; };
65
+ exports.getMode = function(options, spec) {
66
+ if (typeof spec == "string" && mimeModes.hasOwnProperty(spec))
67
+ spec = mimeModes[spec];
68
+ if (typeof spec == "string")
69
+ var mname = spec, config = {};
70
+ else if (spec != null)
71
+ var mname = spec.name, config = spec;
72
+ var mfactory = modes[mname];
73
+ if (!mfactory) throw new Error("Unknown mode: " + spec);
74
+ return mfactory(options, config || {});
75
+ };
76
+
77
+ exports.runMode = function(string, modespec, callback) {
78
+ var mode = exports.getMode({indentUnit: 2}, modespec);
79
+ var lines = splitLines(string), state = exports.startState(mode);
80
+ for (var i = 0, e = lines.length; i < e; ++i) {
81
+ if (i) callback("\n");
82
+ var stream = new exports.StringStream(lines[i]);
83
+ while (!stream.eol()) {
84
+ var style = mode.token(stream, state);
85
+ callback(stream.current(), style, i, stream.start);
86
+ stream.start = stream.pos;
87
+ }
88
+ }
89
+ };
@@ -0,0 +1,60 @@
1
+ // Highlighting text that matches the selection
2
+ //
3
+ // Defines an option highlightSelectionMatches, which, when enabled,
4
+ // will style strings that match the selection throughout the
5
+ // document.
6
+ //
7
+ // The option can be set to true to simply enable it, or to a
8
+ // {minChars, style} object to explicitly configure it. minChars is
9
+ // the minimum amount of characters that should be selected for the
10
+ // behavior to occur, and style is the token style to apply to the
11
+ // matches. This will be prefixed by "cm-" to create an actual CSS
12
+ // class name.
13
+
14
+ (function() {
15
+ var DEFAULT_MIN_CHARS = 2;
16
+ var DEFAULT_TOKEN_STYLE = "matchhighlight";
17
+
18
+ function State(options) {
19
+ this.minChars = typeof options == "object" && options.minChars || DEFAULT_MIN_CHARS;
20
+ this.style = typeof options == "object" && options.style || DEFAULT_TOKEN_STYLE;
21
+ this.overlay = null;
22
+ }
23
+
24
+ CodeMirror.defineOption("highlightSelectionMatches", false, function(cm, val, old) {
25
+ var prev = old && old != CodeMirror.Init;
26
+ if (val && !prev) {
27
+ cm._matchHighlightState = new State(val);
28
+ cm.on("cursorActivity", highlightMatches);
29
+ } else if (!val && prev) {
30
+ var over = cm._matchHighlightState.overlay;
31
+ if (over) cm.removeOverlay(over);
32
+ cm._matchHighlightState = null;
33
+ cm.off("cursorActivity", highlightMatches);
34
+ }
35
+ });
36
+
37
+ function highlightMatches(cm) {
38
+ cm.operation(function() {
39
+ var state = cm._matchHighlightState;
40
+ if (state.overlay) {
41
+ cm.removeOverlay(state.overlay);
42
+ state.overlay = null;
43
+ }
44
+
45
+ if (!cm.somethingSelected()) return;
46
+ var selection = cm.getSelection().replace(/^\s+|\s+$/g, "");
47
+ if (selection.length < state.minChars) return;
48
+
49
+ cm.addOverlay(state.overlay = makeOverlay(selection, state.style));
50
+ });
51
+ }
52
+
53
+ function makeOverlay(query, style) {
54
+ return {token: function(stream) {
55
+ if (stream.match(query)) return style;
56
+ stream.next();
57
+ stream.skipTo(query.charAt(0)) || stream.skipToEnd();
58
+ }};
59
+ }
60
+ })();
@@ -66,7 +66,7 @@
66
66
  var state = getSearchState(cm);
67
67
  var cursor = getSearchCursor(cm, state.query, rev ? state.posFrom : state.posTo);
68
68
  if (!cursor.find(rev)) {
69
- cursor = getSearchCursor(cm, state.query, rev ? {line: cm.lineCount() - 1} : {line: 0, ch: 0});
69
+ cursor = getSearchCursor(cm, state.query, rev ? CodeMirror.Pos(cm.lastLine()) : CodeMirror.Pos(cm.firstLine(), 0));
70
70
  if (!cursor.find(rev)) return;
71
71
  }
72
72
  cm.setSelection(cursor.from(), cursor.to());
@@ -100,7 +100,7 @@
100
100
  } else {
101
101
  clearSearch(cm);
102
102
  var cursor = getSearchCursor(cm, query, cm.getCursor());
103
- function advance() {
103
+ var advance = function() {
104
104
  var start = cursor.from(), match;
105
105
  if (!(match = cursor.findNext())) {
106
106
  cursor = getSearchCursor(cm, query);
@@ -110,12 +110,12 @@
110
110
  cm.setSelection(cursor.from(), cursor.to());
111
111
  confirmDialog(cm, doReplaceConfirm, "Replace?",
112
112
  [function() {doReplace(match);}, advance]);
113
- }
114
- function doReplace(match) {
113
+ };
114
+ var doReplace = function(match) {
115
115
  cursor.replace(typeof query == "string" ? text :
116
116
  text.replace(/\$(\d)/, function(_, i) {return match[i];}));
117
117
  advance();
118
- }
118
+ };
119
119
  advance();
120
120
  }
121
121
  });
@@ -1,9 +1,11 @@
1
1
  (function(){
2
- function SearchCursor(cm, query, pos, caseFold) {
3
- this.atOccurrence = false; this.cm = cm;
2
+ var Pos = CodeMirror.Pos;
3
+
4
+ function SearchCursor(doc, query, pos, caseFold) {
5
+ this.atOccurrence = false; this.doc = doc;
4
6
  if (caseFold == null && typeof query == "string") caseFold = false;
5
7
 
6
- pos = pos ? cm.clipPos(pos) : {line: 0, ch: 0};
8
+ pos = pos ? doc.clipPos(pos) : Pos(0, 0);
7
9
  this.pos = {from: pos, to: pos};
8
10
 
9
11
  // The matches method is filled in based on the type of query.
@@ -15,24 +17,23 @@
15
17
  this.matches = function(reverse, pos) {
16
18
  if (reverse) {
17
19
  query.lastIndex = 0;
18
- var line = cm.getLine(pos.line).slice(0, pos.ch), match = query.exec(line), start = 0;
19
- while (match) {
20
- start += match.index + 1;
21
- line = line.slice(start);
22
- query.lastIndex = 0;
23
- var newmatch = query.exec(line);
24
- if (newmatch) match = newmatch;
25
- else break;
20
+ var line = doc.getLine(pos.line).slice(0, pos.ch), cutOff = 0, match, start;
21
+ for (;;) {
22
+ query.lastIndex = cutOff;
23
+ var newMatch = query.exec(line);
24
+ if (!newMatch) break;
25
+ match = newMatch;
26
+ start = match.index;
27
+ cutOff = match.index + 1;
26
28
  }
27
- start--;
28
29
  } else {
29
30
  query.lastIndex = pos.ch;
30
- var line = cm.getLine(pos.line), match = query.exec(line),
31
+ var line = doc.getLine(pos.line), match = query.exec(line),
31
32
  start = match && match.index;
32
33
  }
33
34
  if (match && match[0])
34
- return {from: {line: pos.line, ch: start},
35
- to: {line: pos.line, ch: start + match[0].length},
35
+ return {from: Pos(pos.line, start),
36
+ to: Pos(pos.line, start + match[0].length),
36
37
  match: match};
37
38
  };
38
39
  } else { // String query
@@ -47,23 +48,23 @@
47
48
  this.matches = function() {};
48
49
  } else {
49
50
  this.matches = function(reverse, pos) {
50
- var line = fold(cm.getLine(pos.line)), len = query.length, match;
51
+ var line = fold(doc.getLine(pos.line)), len = query.length, match;
51
52
  if (reverse ? (pos.ch >= len && (match = line.lastIndexOf(query, pos.ch - len)) != -1)
52
53
  : (match = line.indexOf(query, pos.ch)) != -1)
53
- return {from: {line: pos.line, ch: match},
54
- to: {line: pos.line, ch: match + len}};
54
+ return {from: Pos(pos.line, match),
55
+ to: Pos(pos.line, match + len)};
55
56
  };
56
57
  }
57
58
  } else {
58
59
  this.matches = function(reverse, pos) {
59
- var ln = pos.line, idx = (reverse ? target.length - 1 : 0), match = target[idx], line = fold(cm.getLine(ln));
60
+ var ln = pos.line, idx = (reverse ? target.length - 1 : 0), match = target[idx], line = fold(doc.getLine(ln));
60
61
  var offsetA = (reverse ? line.indexOf(match) + match.length : line.lastIndexOf(match));
61
62
  if (reverse ? offsetA >= pos.ch || offsetA != match.length
62
63
  : offsetA <= pos.ch || offsetA != line.length - match.length)
63
64
  return;
64
65
  for (;;) {
65
- if (reverse ? !ln : ln == cm.lineCount() - 1) return;
66
- line = fold(cm.getLine(ln += reverse ? -1 : 1));
66
+ if (reverse ? !ln : ln == doc.lineCount() - 1) return;
67
+ line = fold(doc.getLine(ln += reverse ? -1 : 1));
67
68
  match = target[reverse ? --idx : ++idx];
68
69
  if (idx > 0 && idx < target.length - 1) {
69
70
  if (line != match) return;
@@ -72,7 +73,7 @@
72
73
  var offsetB = (reverse ? line.lastIndexOf(match) : line.indexOf(match) + match.length);
73
74
  if (reverse ? offsetB != line.length - match.length : offsetB != match.length)
74
75
  return;
75
- var start = {line: pos.line, ch: offsetA}, end = {line: ln, ch: offsetB};
76
+ var start = Pos(pos.line, offsetA), end = Pos(ln, offsetB);
76
77
  return {from: reverse ? end : start, to: reverse ? start : end};
77
78
  }
78
79
  };
@@ -85,9 +86,9 @@
85
86
  findPrevious: function() {return this.find(true);},
86
87
 
87
88
  find: function(reverse) {
88
- var self = this, pos = this.cm.clipPos(reverse ? this.pos.from : this.pos.to);
89
+ var self = this, pos = this.doc.clipPos(reverse ? this.pos.from : this.pos.to);
89
90
  function savePosAndFail(line) {
90
- var pos = {line: line, ch: 0};
91
+ var pos = Pos(line, 0);
91
92
  self.pos = {from: pos, to: pos};
92
93
  self.atOccurrence = false;
93
94
  return false;
@@ -95,17 +96,18 @@
95
96
 
96
97
  for (;;) {
97
98
  if (this.pos = this.matches(reverse, pos)) {
99
+ if (!this.pos.from || !this.pos.to) { console.log(this.matches, this.pos); }
98
100
  this.atOccurrence = true;
99
101
  return this.pos.match || true;
100
102
  }
101
103
  if (reverse) {
102
104
  if (!pos.line) return savePosAndFail(0);
103
- pos = {line: pos.line-1, ch: this.cm.getLine(pos.line-1).length};
105
+ pos = Pos(pos.line-1, this.doc.getLine(pos.line-1).length);
104
106
  }
105
107
  else {
106
- var maxLine = this.cm.lineCount();
108
+ var maxLine = this.doc.lineCount();
107
109
  if (pos.line == maxLine - 1) return savePosAndFail(maxLine);
108
- pos = {line: pos.line+1, ch: 0};
110
+ pos = Pos(pos.line + 1, 0);
109
111
  }
110
112
  }
111
113
  },
@@ -114,13 +116,18 @@
114
116
  to: function() {if (this.atOccurrence) return this.pos.to;},
115
117
 
116
118
  replace: function(newText) {
117
- var self = this;
118
- if (this.atOccurrence)
119
- self.pos.to = this.cm.replaceRange(newText, self.pos.from, self.pos.to);
119
+ if (!this.atOccurrence) return;
120
+ var lines = CodeMirror.splitLines(newText);
121
+ this.doc.replaceRange(lines, this.pos.from, this.pos.to);
122
+ this.pos.to = Pos(this.pos.from.line + lines.length - 1,
123
+ lines[lines.length - 1].length + (lines.length == 1 ? this.pos.from.ch : 0));
120
124
  }
121
125
  };
122
126
 
123
127
  CodeMirror.defineExtension("getSearchCursor", function(query, pos, caseFold) {
128
+ return new SearchCursor(this.doc, query, pos, caseFold);
129
+ });
130
+ CodeMirror.defineDocExtension("getSearchCursor", function(query, pos, caseFold) {
124
131
  return new SearchCursor(this, query, pos, caseFold);
125
132
  });
126
133
  })();
@@ -0,0 +1,39 @@
1
+ // Because sometimes you need to style the cursor's line.
2
+ //
3
+ // Adds an option 'styleActiveLine' which, when enabled, gives the
4
+ // active line's wrapping <div> the CSS class "CodeMirror-activeline",
5
+ // and gives its background <div> the class "CodeMirror-activeline-background".
6
+
7
+ (function() {
8
+ "use strict";
9
+ var WRAP_CLASS = "CodeMirror-activeline";
10
+ var BACK_CLASS = "CodeMirror-activeline-background";
11
+
12
+ CodeMirror.defineOption("styleActiveLine", false, function(cm, val, old) {
13
+ var prev = old && old != CodeMirror.Init;
14
+ if (val && !prev) {
15
+ updateActiveLine(cm);
16
+ cm.on("cursorActivity", updateActiveLine);
17
+ } else if (!val && prev) {
18
+ cm.off("cursorActivity", updateActiveLine);
19
+ clearActiveLine(cm);
20
+ delete cm._activeLine;
21
+ }
22
+ });
23
+
24
+ function clearActiveLine(cm) {
25
+ if ("_activeLine" in cm) {
26
+ cm.removeLineClass(cm._activeLine, "wrap", WRAP_CLASS);
27
+ cm.removeLineClass(cm._activeLine, "background", BACK_CLASS);
28
+ }
29
+ }
30
+
31
+ function updateActiveLine(cm) {
32
+ var line = cm.getLineHandle(cm.getCursor().line);
33
+ if (cm._activeLine == line) return;
34
+ clearActiveLine(cm);
35
+ cm.addLineClass(line, "wrap", WRAP_CLASS);
36
+ cm.addLineClass(line, "background", BACK_CLASS);
37
+ cm._activeLine = line;
38
+ }
39
+ })();
@@ -0,0 +1,34 @@
1
+ // Because sometimes you need to mark the selected *text*.
2
+ //
3
+ // Adds an option 'styleSelectedText' which, when enabled, gives
4
+ // selected text the CSS class "CodeMirror-selectedtext".
5
+
6
+ (function() {
7
+ "use strict";
8
+
9
+ CodeMirror.defineOption("styleSelectedText", false, function(cm, val, old) {
10
+ var prev = old && old != CodeMirror.Init;
11
+ if (val && !prev) {
12
+ updateSelectedText(cm);
13
+ cm.on("cursorActivity", updateSelectedText);
14
+ } else if (!val && prev) {
15
+ cm.off("cursorActivity", updateSelectedText);
16
+ clearSelectedText(cm);
17
+ delete cm._selectionMark;
18
+ }
19
+ });
20
+
21
+ function clearSelectedText(cm) {
22
+ if (cm._selectionMark) cm._selectionMark.clear();
23
+ }
24
+
25
+ function updateSelectedText(cm) {
26
+ clearSelectedText(cm);
27
+
28
+ if (cm.somethingSelected())
29
+ cm._selectionMark = cm.markText(cm.getCursor("start"), cm.getCursor("end"),
30
+ {className: "CodeMirror-selectedtext"});
31
+ else
32
+ cm._selectionMark = null;
33
+ }
34
+ })();