codemirror-rails 3.02 → 3.12

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -2,7 +2,7 @@
2
2
  function forEach(arr, f) {
3
3
  for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]);
4
4
  }
5
-
5
+
6
6
  function arrayContains(arr, item) {
7
7
  if (!Array.prototype.indexOf) {
8
8
  var i = arr.length;
@@ -25,11 +25,11 @@
25
25
  token = tprop = {start: cur.ch, end: cur.ch, string: "", state: token.state,
26
26
  className: token.string == ":" ? "pig-type" : null};
27
27
  }
28
-
28
+
29
29
  if (!context) var context = [];
30
30
  context.push(tprop);
31
-
32
- var completionList = getCompletions(token, context);
31
+
32
+ var completionList = getCompletions(token, context);
33
33
  completionList = completionList.sort();
34
34
  //prevent autocomplete for last word, instead show dropdown with one word
35
35
  if(completionList.length == 1) {
@@ -37,27 +37,27 @@
37
37
  }
38
38
 
39
39
  return {list: completionList,
40
- from: {line: cur.line, ch: token.start},
41
- to: {line: cur.line, ch: token.end}};
40
+ from: CodeMirror.Pos(cur.line, token.start),
41
+ to: CodeMirror.Pos(cur.line, token.end)};
42
42
  }
43
-
43
+
44
44
  CodeMirror.pigHint = function(editor) {
45
45
  return scriptHint(editor, pigKeywordsU, function (e, cur) {return e.getTokenAt(cur);});
46
46
  };
47
-
47
+
48
48
  var pigKeywords = "VOID IMPORT RETURNS DEFINE LOAD FILTER FOREACH ORDER CUBE DISTINCT COGROUP "
49
49
  + "JOIN CROSS UNION SPLIT INTO IF OTHERWISE ALL AS BY USING INNER OUTER ONSCHEMA PARALLEL "
50
50
  + "PARTITION GROUP AND OR NOT GENERATE FLATTEN ASC DESC IS STREAM THROUGH STORE MAPREDUCE "
51
- + "SHIP CACHE INPUT OUTPUT STDERROR STDIN STDOUT LIMIT SAMPLE LEFT RIGHT FULL EQ GT LT GTE LTE "
51
+ + "SHIP CACHE INPUT OUTPUT STDERROR STDIN STDOUT LIMIT SAMPLE LEFT RIGHT FULL EQ GT LT GTE LTE "
52
52
  + "NEQ MATCHES TRUE FALSE";
53
53
  var pigKeywordsU = pigKeywords.split(" ");
54
54
  var pigKeywordsL = pigKeywords.toLowerCase().split(" ");
55
-
55
+
56
56
  var pigTypes = "BOOLEAN INT LONG FLOAT DOUBLE CHARARRAY BYTEARRAY BAG TUPLE MAP";
57
57
  var pigTypesU = pigTypes.split(" ");
58
58
  var pigTypesL = pigTypes.toLowerCase().split(" ");
59
-
60
- var pigBuiltins = "ABS ACOS ARITY ASIN ATAN AVG BAGSIZE BINSTORAGE BLOOM BUILDBLOOM CBRT CEIL "
59
+
60
+ var pigBuiltins = "ABS ACOS ARITY ASIN ATAN AVG BAGSIZE BINSTORAGE BLOOM BUILDBLOOM CBRT CEIL "
61
61
  + "CONCAT COR COS COSH COUNT COUNT_STAR COV CONSTANTSIZE CUBEDIMENSIONS DIFF DISTINCT DOUBLEABS "
62
62
  + "DOUBLEAVG DOUBLEBASE DOUBLEMAX DOUBLEMIN DOUBLEROUND DOUBLESUM EXP FLOOR FLOATABS FLOATAVG "
63
63
  + "FLOATMAX FLOATMIN FLOATROUND FLOATSUM GENERICINVOKER INDEXOF INTABS INTAVG INTMAX INTMIN "
@@ -66,9 +66,9 @@
66
66
  + "LONGAVG LONGMAX LONGMIN LONGSUM MAX MIN MAPSIZE MONITOREDUDF NONDETERMINISTIC OUTPUTSCHEMA "
67
67
  + "PIGSTORAGE PIGSTREAMING RANDOM REGEX_EXTRACT REGEX_EXTRACT_ALL REPLACE ROUND SIN SINH SIZE "
68
68
  + "SQRT STRSPLIT SUBSTRING SUM STRINGCONCAT STRINGMAX STRINGMIN STRINGSIZE TAN TANH TOBAG "
69
- + "TOKENIZE TOMAP TOP TOTUPLE TRIM TEXTLOADER TUPLESIZE UCFIRST UPPER UTF8STORAGECONVERTER";
70
- var pigBuiltinsU = pigBuiltins.split(" ").join("() ").split(" ");
71
- var pigBuiltinsL = pigBuiltins.toLowerCase().split(" ").join("() ").split(" ");
69
+ + "TOKENIZE TOMAP TOP TOTUPLE TRIM TEXTLOADER TUPLESIZE UCFIRST UPPER UTF8STORAGECONVERTER";
70
+ var pigBuiltinsU = pigBuiltins.split(" ").join("() ").split(" ");
71
+ var pigBuiltinsL = pigBuiltins.toLowerCase().split(" ").join("() ").split(" ");
72
72
  var pigBuiltinsC = ("BagSize BinStorage Bloom BuildBloom ConstantSize CubeDimensions DoubleAbs "
73
73
  + "DoubleAvg DoubleBase DoubleMax DoubleMin DoubleRound DoubleSum FloatAbs FloatAvg FloatMax "
74
74
  + "FloatMin FloatRound FloatSum GenericInvoker IntAbs IntAvg IntMax IntMin IntSum "
@@ -76,13 +76,13 @@
76
76
  + "IsEmpty JsonLoader JsonMetadata JsonStorage LongAbs LongAvg LongMax LongMin LongSum MapSize "
77
77
  + "MonitoredUDF Nondeterministic OutputSchema PigStorage PigStreaming StringConcat StringMax "
78
78
  + "StringMin StringSize TextLoader TupleSize Utf8StorageConverter").split(" ").join("() ").split(" ");
79
-
79
+
80
80
  function getCompletions(token, context) {
81
81
  var found = [], start = token.string;
82
82
  function maybeAdd(str) {
83
83
  if (str.indexOf(start) == 0 && !arrayContains(found, str)) found.push(str);
84
84
  }
85
-
85
+
86
86
  function gatherCompletions(obj) {
87
87
  if(obj == ":") {
88
88
  forEach(pigTypesL, maybeAdd);
@@ -103,11 +103,11 @@
103
103
  // find in the current environment.
104
104
  var obj = context.pop(), base;
105
105
 
106
- if (obj.type == "variable")
106
+ if (obj.type == "variable")
107
107
  base = obj.string;
108
108
  else if(obj.type == "variable-3")
109
109
  base = ":" + obj.string;
110
-
110
+
111
111
  while (base != null && context.length)
112
112
  base = base[context.pop().string];
113
113
  if (base != null) gatherCompletions(base);
@@ -37,8 +37,8 @@
37
37
  }
38
38
 
39
39
  return {list: completionList,
40
- from: {line: cur.line, ch: token.start},
41
- to: {line: cur.line, ch: token.end}};
40
+ from: CodeMirror.Pos(cur.line, token.start),
41
+ to: CodeMirror.Pos(cur.line, token.end)};
42
42
  }
43
43
 
44
44
  CodeMirror.pythonHint = function(editor) {
@@ -0,0 +1,180 @@
1
+ CodeMirror.showHint = function(cm, getHints, options) {
2
+ if (!options) options = {};
3
+ var startCh = cm.getCursor().ch, continued = false;
4
+ var closeOn = options.closeCharacters || /[\s()\[\]{};:]/;
5
+
6
+ function startHinting() {
7
+ // We want a single cursor position.
8
+ if (cm.somethingSelected()) return;
9
+
10
+ if (options.async)
11
+ getHints(cm, showHints, options);
12
+ else
13
+ return showHints(getHints(cm, options));
14
+ }
15
+
16
+ function getText(completion) {
17
+ if (typeof completion == "string") return completion;
18
+ else return completion.text;
19
+ }
20
+
21
+ function pickCompletion(cm, data, completion) {
22
+ if (completion.hint) completion.hint(cm, data, completion);
23
+ else cm.replaceRange(getText(completion), data.from, data.to);
24
+ }
25
+
26
+ function showHints(data) {
27
+ if (!data || !data.list.length) return;
28
+ var completions = data.list;
29
+ // When there is only one completion, use it directly.
30
+ if (!continued && options.completeSingle !== false && completions.length == 1) {
31
+ pickCompletion(cm, data, completions[0]);
32
+ CodeMirror.signal(data, "close");
33
+ return true;
34
+ }
35
+
36
+ // Build the select widget
37
+ var hints = document.createElement("ul"), selectedHint = 0;
38
+ hints.className = "CodeMirror-hints";
39
+ for (var i = 0; i < completions.length; ++i) {
40
+ var elt = hints.appendChild(document.createElement("li")), completion = completions[i];
41
+ var className = "CodeMirror-hint" + (i ? "" : " CodeMirror-hint-active");
42
+ if (completion.className != null) className = completion.className + " " + className;
43
+ elt.className = className;
44
+ if (completion.render) completion.render(elt, data, completion);
45
+ else elt.appendChild(document.createTextNode(completion.displayText || getText(completion)));
46
+ elt.hintId = i;
47
+ }
48
+ var pos = cm.cursorCoords(options.alignWithWord !== false ? data.from : null);
49
+ var left = pos.left, top = pos.bottom, below = true;
50
+ hints.style.left = left + "px";
51
+ hints.style.top = top + "px";
52
+ document.body.appendChild(hints);
53
+ CodeMirror.signal(data, "shown");
54
+
55
+ // If we're at the edge of the screen, then we want the menu to appear on the left of the cursor.
56
+ var winW = window.innerWidth || Math.max(document.body.offsetWidth, document.documentElement.offsetWidth);
57
+ var winH = window.innerHeight || Math.max(document.body.offsetHeight, document.documentElement.offsetHeight);
58
+ var box = hints.getBoundingClientRect();
59
+ var overlapX = box.right - winW, overlapY = box.bottom - winH;
60
+ if (overlapX > 0) {
61
+ if (box.right - box.left > winW) {
62
+ hints.style.width = (winW - 5) + "px";
63
+ overlapX -= (box.right - box.left) - winW;
64
+ }
65
+ hints.style.left = (left = pos.left - overlapX) + "px";
66
+ }
67
+ if (overlapY > 0) {
68
+ var height = box.bottom - box.top;
69
+ if (box.top - (pos.bottom - pos.top) - height > 0) {
70
+ overlapY = height + (pos.bottom - pos.top);
71
+ below = false;
72
+ } else if (height > winH) {
73
+ hints.style.height = (winH - 5) + "px";
74
+ overlapY -= height - winH;
75
+ }
76
+ hints.style.top = (top = pos.bottom - overlapY) + "px";
77
+ }
78
+
79
+ function changeActive(i) {
80
+ i = Math.max(0, Math.min(i, completions.length - 1));
81
+ if (selectedHint == i) return;
82
+ var node = hints.childNodes[selectedHint];
83
+ node.className = node.className.replace(" CodeMirror-hint-active", "");
84
+ node = hints.childNodes[selectedHint = i];
85
+ node.className += " CodeMirror-hint-active";
86
+ if (node.offsetTop < hints.scrollTop)
87
+ hints.scrollTop = node.offsetTop - 3;
88
+ else if (node.offsetTop + node.offsetHeight > hints.scrollTop + hints.clientHeight)
89
+ hints.scrollTop = node.offsetTop + node.offsetHeight - hints.clientHeight + 3;
90
+ CodeMirror.signal(data, "select", completions[selectedHint], node);
91
+ }
92
+
93
+ function screenAmount() {
94
+ return Math.floor(hints.clientHeight / hints.firstChild.offsetHeight) || 1;
95
+ }
96
+
97
+ var ourMap, baseMap = {
98
+ Up: function() {changeActive(selectedHint - 1);},
99
+ Down: function() {changeActive(selectedHint + 1);},
100
+ PageUp: function() {changeActive(selectedHint - screenAmount());},
101
+ PageDown: function() {changeActive(selectedHint + screenAmount());},
102
+ Home: function() {changeActive(0);},
103
+ End: function() {changeActive(completions.length - 1);},
104
+ Enter: pick,
105
+ Tab: pick,
106
+ Esc: close
107
+ };
108
+ if (options.customKeys) {
109
+ ourMap = {};
110
+ for (var key in options.customKeys) if (options.customKeys.hasOwnProperty(key)) {
111
+ var val = options.customKeys[key];
112
+ if (baseMap.hasOwnProperty(val)) val = baseMap[val];
113
+ ourMap[key] = val;
114
+ }
115
+ } else ourMap = baseMap;
116
+
117
+ cm.addKeyMap(ourMap);
118
+ cm.on("cursorActivity", cursorActivity);
119
+ var closingOnBlur;
120
+ function onBlur(){ closingOnBlur = setTimeout(close, 100); };
121
+ function onFocus(){ clearTimeout(closingOnBlur); };
122
+ cm.on("blur", onBlur);
123
+ cm.on("focus", onFocus);
124
+ var startScroll = cm.getScrollInfo();
125
+ function onScroll() {
126
+ var curScroll = cm.getScrollInfo(), editor = cm.getWrapperElement().getBoundingClientRect();
127
+ var newTop = top + startScroll.top - curScroll.top, point = newTop;
128
+ if (!below) point += hints.offsetHeight;
129
+ if (point <= editor.top || point >= editor.bottom) return close();
130
+ hints.style.top = newTop + "px";
131
+ hints.style.left = (left + startScroll.left - curScroll.left) + "px";
132
+ }
133
+ cm.on("scroll", onScroll);
134
+ CodeMirror.on(hints, "dblclick", function(e) {
135
+ var t = e.target || e.srcElement;
136
+ if (t.hintId != null) {selectedHint = t.hintId; pick();}
137
+ });
138
+ CodeMirror.on(hints, "click", function(e) {
139
+ var t = e.target || e.srcElement;
140
+ if (t.hintId != null) changeActive(t.hintId);
141
+ });
142
+ CodeMirror.on(hints, "mousedown", function() {
143
+ setTimeout(function(){cm.focus();}, 20);
144
+ });
145
+
146
+ var done = false, once;
147
+ function close(willContinue) {
148
+ if (done) return;
149
+ done = true;
150
+ clearTimeout(once);
151
+ hints.parentNode.removeChild(hints);
152
+ cm.removeKeyMap(ourMap);
153
+ cm.off("cursorActivity", cursorActivity);
154
+ cm.off("blur", onBlur);
155
+ cm.off("focus", onFocus);
156
+ cm.off("scroll", onScroll);
157
+ if (willContinue !== true) CodeMirror.signal(data, "close");
158
+ }
159
+ function pick() {
160
+ pickCompletion(cm, data, completions[selectedHint]);
161
+ close();
162
+ }
163
+ var once, lastPos = cm.getCursor(), lastLen = cm.getLine(lastPos.line).length;
164
+ function cursorActivity() {
165
+ clearTimeout(once);
166
+
167
+ var pos = cm.getCursor(), line = cm.getLine(pos.line);
168
+ if (pos.line != lastPos.line || line.length - pos.ch != lastLen - lastPos.ch ||
169
+ pos.ch < startCh || cm.somethingSelected() ||
170
+ (pos.ch && closeOn.test(line.charAt(pos.ch - 1))))
171
+ close();
172
+ else
173
+ once = setTimeout(function(){close(true); continued = true; startHinting();}, 70);
174
+ }
175
+ CodeMirror.signal(data, "select", completions[0], hints.firstChild);
176
+ return true;
177
+ }
178
+
179
+ return startHinting();
180
+ };
@@ -1,27 +1,14 @@
1
-
2
1
  (function() {
3
2
 
4
3
  CodeMirror.xmlHints = [];
5
4
 
6
- CodeMirror.xmlHint = function(cm, simbol) {
7
-
8
- if(simbol.length > 0) {
9
- var cursor = cm.getCursor();
10
- cm.replaceSelection(simbol);
11
- cursor = {line: cursor.line, ch: cursor.ch + 1};
12
- cm.setCursor(cursor);
13
- }
14
-
15
- CodeMirror.simpleHint(cm, getHint);
16
- };
17
-
18
- var getHint = function(cm) {
5
+ CodeMirror.xmlHint = function(cm) {
19
6
 
20
7
  var cursor = cm.getCursor();
21
8
 
22
9
  if (cursor.ch > 0) {
23
10
 
24
- var text = cm.getRange({line: 0, ch: 0}, cursor);
11
+ var text = cm.getRange(CodeMirror.Pos(0, 0), cursor);
25
12
  var typed = '';
26
13
  var simbol = '';
27
14
  for(var i = text.length - 1; i >= 0; i--) {
@@ -51,10 +38,10 @@
51
38
 
52
39
  return {
53
40
  list: hints,
54
- from: { line: cursor.line, ch: cursor.ch - typed.length },
41
+ from: CodeMirror.Pos(cursor.line, cursor.ch - typed.length),
55
42
  to: cursor
56
43
  };
57
- };
44
+ }
58
45
  };
59
46
 
60
47
  var getActiveElement = function(text) {
@@ -63,7 +50,7 @@
63
50
 
64
51
  if(text.length >= 0) {
65
52
 
66
- var regex = new RegExp('<([^!?][^\\s/>]*).*?>', 'g');
53
+ var regex = new RegExp('<([^!?][^\\s/>]*)[\\s\\S]*?>', 'g');
67
54
 
68
55
  var matches = [];
69
56
  var match;
@@ -0,0 +1,127 @@
1
+ (function() {
2
+
3
+ var bogus = [ "Dangerous comment" ];
4
+
5
+ var warnings = [ [ "Expected '{'",
6
+ "Statement body should be inside '{ }' braces." ] ];
7
+
8
+ var errors = [ "Missing semicolon", "Extra comma", "Missing property name",
9
+ "Unmatched ", " and instead saw", " is not defined",
10
+ "Unclosed string", "Stopping, unable to continue" ];
11
+
12
+ function validator(options, text) {
13
+ JSHINT(text, options);
14
+ var errors = JSHINT.data().errors, result = [];
15
+ if (errors) parseErrors(errors, result);
16
+ return result;
17
+ }
18
+
19
+ CodeMirror.javascriptValidatorWithOptions = function(options) {
20
+ return function(text) { return validator(options, text); };
21
+ };
22
+
23
+ CodeMirror.javascriptValidator = CodeMirror.javascriptValidatorWithOptions(null);
24
+
25
+ function cleanup(error) {
26
+ // All problems are warnings by default
27
+ fixWith(error, warnings, "warning", true);
28
+ fixWith(error, errors, "error");
29
+
30
+ return isBogus(error) ? null : error;
31
+ }
32
+
33
+ function fixWith(error, fixes, severity, force) {
34
+ var description, fix, find, replace, found;
35
+
36
+ description = error.description;
37
+
38
+ for ( var i = 0; i < fixes.length; i++) {
39
+ fix = fixes[i];
40
+ find = (typeof fix === "string" ? fix : fix[0]);
41
+ replace = (typeof fix === "string" ? null : fix[1]);
42
+ found = description.indexOf(find) !== -1;
43
+
44
+ if (force || found) {
45
+ error.severity = severity;
46
+ }
47
+ if (found && replace) {
48
+ error.description = replace;
49
+ }
50
+ }
51
+ }
52
+
53
+ function isBogus(error) {
54
+ var description = error.description;
55
+ for ( var i = 0; i < bogus.length; i++) {
56
+ if (description.indexOf(bogus[i]) !== -1) {
57
+ return true;
58
+ }
59
+ }
60
+ return false;
61
+ }
62
+
63
+ function parseErrors(errors, output) {
64
+ for ( var i = 0; i < errors.length; i++) {
65
+ var error = errors[i];
66
+ if (error) {
67
+ var linetabpositions, index;
68
+
69
+ linetabpositions = [];
70
+
71
+ // This next block is to fix a problem in jshint. Jshint
72
+ // replaces
73
+ // all tabs with spaces then performs some checks. The error
74
+ // positions (character/space) are then reported incorrectly,
75
+ // not taking the replacement step into account. Here we look
76
+ // at the evidence line and try to adjust the character position
77
+ // to the correct value.
78
+ if (error.evidence) {
79
+ // Tab positions are computed once per line and cached
80
+ var tabpositions = linetabpositions[error.line];
81
+ if (!tabpositions) {
82
+ var evidence = error.evidence;
83
+ tabpositions = [];
84
+ // ugggh phantomjs does not like this
85
+ // forEachChar(evidence, function(item, index) {
86
+ Array.prototype.forEach.call(evidence, function(item,
87
+ index) {
88
+ if (item === '\t') {
89
+ // First col is 1 (not 0) to match error
90
+ // positions
91
+ tabpositions.push(index + 1);
92
+ }
93
+ });
94
+ linetabpositions[error.line] = tabpositions;
95
+ }
96
+ if (tabpositions.length > 0) {
97
+ var pos = error.character;
98
+ tabpositions.forEach(function(tabposition) {
99
+ if (pos > tabposition) pos -= 1;
100
+ });
101
+ error.character = pos;
102
+ }
103
+ }
104
+
105
+ var start = error.character - 1, end = start + 1;
106
+ if (error.evidence) {
107
+ index = error.evidence.substring(start).search(/.\b/);
108
+ if (index > -1) {
109
+ end += index;
110
+ }
111
+ }
112
+
113
+ // Convert to format expected by validation service
114
+ error.description = error.reason;// + "(jshint)";
115
+ error.start = error.character;
116
+ error.end = end;
117
+ error = cleanup(error);
118
+
119
+ if (error)
120
+ output.push({message: error.description,
121
+ severity: error.severity,
122
+ from: CodeMirror.Pos(error.line - 1, start),
123
+ to: CodeMirror.Pos(error.line - 1, end)});
124
+ }
125
+ }
126
+ }
127
+ })();
@@ -0,0 +1,14 @@
1
+ // Depends on jsonlint.js from https://github.com/zaach/jsonlint
2
+
3
+ CodeMirror.jsonValidator = function(text) {
4
+ var found = [];
5
+ jsonlint.parseError = function(str, hash) {
6
+ var loc = hash.loc;
7
+ found.push({from: CodeMirror.Pos(loc.first_line - 1, loc.first_column),
8
+ to: CodeMirror.Pos(loc.last_line - 1, loc.last_column),
9
+ message: str});
10
+ };
11
+ try { jsonlint.parse(text); }
12
+ catch(e) {}
13
+ return found;
14
+ };
@@ -0,0 +1,197 @@
1
+ CodeMirror.validate = (function() {
2
+ var GUTTER_ID = "CodeMirror-lint-markers";
3
+ var SEVERITIES = /^(?:error|warning)$/;
4
+
5
+ function showTooltip(e, content) {
6
+ var tt = document.createElement("div");
7
+ tt.className = "CodeMirror-lint-tooltip";
8
+ tt.appendChild(content.cloneNode(true));
9
+ document.body.appendChild(tt);
10
+
11
+ function position(e) {
12
+ if (!tt.parentNode) return CodeMirror.off(document, "mousemove", position);
13
+ tt.style.top = Math.max(0, e.clientY - tt.offsetHeight - 5) + "px";
14
+ tt.style.left = (e.clientX + 5) + "px";
15
+ }
16
+ CodeMirror.on(document, "mousemove", position);
17
+ position(e);
18
+ if (tt.style.opacity != null) tt.style.opacity = 1;
19
+ return tt;
20
+ }
21
+ function rm(elt) {
22
+ if (elt.parentNode) elt.parentNode.removeChild(elt);
23
+ }
24
+ function hideTooltip(tt) {
25
+ if (!tt.parentNode) return;
26
+ if (tt.style.opacity == null) rm(tt);
27
+ tt.style.opacity = 0;
28
+ setTimeout(function() { rm(tt); }, 600);
29
+ }
30
+
31
+ function showTooltipFor(e, content, node) {
32
+ var tooltip = showTooltip(e, content);
33
+ function hide() {
34
+ CodeMirror.off(node, "mouseout", hide);
35
+ if (tooltip) { hideTooltip(tooltip); tooltip = null; }
36
+ }
37
+ var poll = setInterval(function() {
38
+ if (tooltip) for (var n = node;; n = n.parentNode) {
39
+ if (n == document.body) return;
40
+ if (!n) { hide(); break; }
41
+ }
42
+ if (!tooltip) return clearInterval(poll);
43
+ }, 400);
44
+ CodeMirror.on(node, "mouseout", hide);
45
+ }
46
+
47
+ function LintState(cm, options, hasGutter) {
48
+ this.marked = [];
49
+ this.options = options;
50
+ this.timeout = null;
51
+ this.hasGutter = hasGutter;
52
+ this.onMouseOver = function(e) { onMouseOver(cm, e); };
53
+ }
54
+
55
+ function parseOptions(options) {
56
+ if (options instanceof Function) return {getAnnotations: options};
57
+ else if (!options || !options.getAnnotations) throw new Error("Required option 'getAnnotations' missing (lint addon)");
58
+ return options;
59
+ }
60
+
61
+ function clearMarks(cm) {
62
+ var state = cm._lintState;
63
+ if (state.hasGutter) cm.clearGutter(GUTTER_ID);
64
+ for (var i = 0; i < state.marked.length; ++i)
65
+ state.marked[i].clear();
66
+ state.marked.length = 0;
67
+ }
68
+
69
+ function makeMarker(labels, severity, multiple, tooltips) {
70
+ var marker = document.createElement("div"), inner = marker;
71
+ marker.className = "CodeMirror-lint-marker-" + severity;
72
+ if (multiple) {
73
+ inner = marker.appendChild(document.createElement("div"));
74
+ inner.className = "CodeMirror-lint-marker-multiple";
75
+ }
76
+
77
+ if (tooltips != false) CodeMirror.on(inner, "mouseover", function(e) {
78
+ showTooltipFor(e, labels, inner);
79
+ });
80
+
81
+ return marker;
82
+ }
83
+
84
+ function getMaxSeverity(a, b) {
85
+ if (a == "error") return a;
86
+ else return b;
87
+ }
88
+
89
+ function groupByLine(annotations) {
90
+ var lines = [];
91
+ for (var i = 0; i < annotations.length; ++i) {
92
+ var ann = annotations[i], line = ann.from.line;
93
+ (lines[line] || (lines[line] = [])).push(ann);
94
+ }
95
+ return lines;
96
+ }
97
+
98
+ function annotationTooltip(ann) {
99
+ var severity = ann.severity;
100
+ if (!SEVERITIES.test(severity)) severity = "error";
101
+ var tip = document.createElement("div");
102
+ tip.className = "CodeMirror-lint-message-" + severity;
103
+ tip.appendChild(document.createTextNode(ann.message));
104
+ return tip;
105
+ }
106
+
107
+ function startLinting(cm) {
108
+ var state = cm._lintState, options = state.options;
109
+ if (options.async)
110
+ options.getAnnotations(cm, updateLinting, options);
111
+ else
112
+ updateLinting(cm, options.getAnnotations(cm.getValue()));
113
+ }
114
+
115
+ function updateLinting(cm, annotationsNotSorted) {
116
+ clearMarks(cm);
117
+ var state = cm._lintState, options = state.options;
118
+
119
+ var annotations = groupByLine(annotationsNotSorted);
120
+
121
+ for (var line = 0; line < annotations.length; ++line) {
122
+ var anns = annotations[line];
123
+ if (!anns) continue;
124
+
125
+ var maxSeverity = null;
126
+ var tipLabel = state.hasGutter && document.createDocumentFragment();
127
+
128
+ for (var i = 0; i < anns.length; ++i) {
129
+ var ann = anns[i];
130
+ var severity = ann.severity;
131
+ if (!SEVERITIES.test(severity)) severity = "error";
132
+ maxSeverity = getMaxSeverity(maxSeverity, severity);
133
+
134
+ if (options.formatAnnotation) ann = options.formatAnnotation(ann);
135
+ if (state.hasGutter) tipLabel.appendChild(annotationTooltip(ann));
136
+
137
+ if (ann.to) state.marked.push(cm.markText(ann.from, ann.to, {
138
+ className: "CodeMirror-lint-span-" + severity,
139
+ __annotation: ann
140
+ }));
141
+ }
142
+
143
+ if (state.hasGutter)
144
+ cm.setGutterMarker(line, GUTTER_ID, makeMarker(tipLabel, maxSeverity, anns.length > 1,
145
+ state.options.tooltips));
146
+ }
147
+ if (options.onUpdateLinting) options.onUpdateLinting(annotationsNotSorted, annotations, cm);
148
+ }
149
+
150
+ function onChange(cm) {
151
+ var state = cm._lintState;
152
+ clearTimeout(state.timeout);
153
+ state.timeout = setTimeout(function(){startLinting(cm);}, state.options.delay || 500);
154
+ }
155
+
156
+ function popupSpanTooltip(ann, e) {
157
+ var target = e.target || e.srcElement;
158
+ showTooltipFor(e, annotationTooltip(ann), target);
159
+ }
160
+
161
+ // When the mouseover fires, the cursor might not actually be over
162
+ // the character itself yet. These pairs of x,y offsets are used to
163
+ // probe a few nearby points when no suitable marked range is found.
164
+ var nearby = [0, 0, 0, 5, 0, -5, 5, 0, -5, 0];
165
+
166
+ function onMouseOver(cm, e) {
167
+ if (!/\bCodeMirror-lint-span-/.test((e.target || e.srcElement).className)) return;
168
+ for (var i = 0; i < nearby.length; i += 2) {
169
+ var spans = cm.findMarksAt(cm.coordsChar({left: e.clientX + nearby[i],
170
+ top: e.clientY + nearby[i + 1]}));
171
+ for (var j = 0; j < spans.length; ++j) {
172
+ var span = spans[j], ann = span.__annotation;
173
+ if (ann) return popupSpanTooltip(ann, e);
174
+ }
175
+ }
176
+ }
177
+
178
+ CodeMirror.defineOption("lintWith", false, function(cm, val, old) {
179
+ if (old && old != CodeMirror.Init) {
180
+ clearMarks(cm);
181
+ cm.off("change", onChange);
182
+ CodeMirror.off(cm.getWrapperElement(), "mouseover", cm._lintState.onMouseOver);
183
+ delete cm._lintState;
184
+ }
185
+
186
+ if (val) {
187
+ var gutters = cm.getOption("gutters"), hasLintGutter = false;
188
+ for (var i = 0; i < gutters.length; ++i) if (gutters[i] == GUTTER_ID) hasLintGutter = true;
189
+ var state = cm._lintState = new LintState(cm, parseOptions(val), hasLintGutter);
190
+ cm.on("change", onChange);
191
+ if (state.options.tooltips != false)
192
+ CodeMirror.on(cm.getWrapperElement(), "mouseover", state.onMouseOver);
193
+
194
+ startLinting(cm);
195
+ }
196
+ });
197
+ })();