codemirror-rails 4.1 → 4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/lib/codemirror/rails/version.rb +2 -2
  3. data/vendor/assets/javascripts/codemirror.js +133 -58
  4. data/vendor/assets/javascripts/codemirror/addons/comment/comment.js +3 -0
  5. data/vendor/assets/javascripts/codemirror/addons/comment/continuecomment.js +3 -0
  6. data/vendor/assets/javascripts/codemirror/addons/dialog/dialog.js +3 -0
  7. data/vendor/assets/javascripts/codemirror/addons/display/fullscreen.js +3 -0
  8. data/vendor/assets/javascripts/codemirror/addons/display/placeholder.js +3 -0
  9. data/vendor/assets/javascripts/codemirror/addons/display/rulers.js +16 -6
  10. data/vendor/assets/javascripts/codemirror/addons/edit/closebrackets.js +3 -0
  11. data/vendor/assets/javascripts/codemirror/addons/edit/closetag.js +28 -3
  12. data/vendor/assets/javascripts/codemirror/addons/edit/continuelist.js +3 -0
  13. data/vendor/assets/javascripts/codemirror/addons/edit/matchbrackets.js +3 -0
  14. data/vendor/assets/javascripts/codemirror/addons/edit/matchtags.js +3 -0
  15. data/vendor/assets/javascripts/codemirror/addons/edit/trailingspace.js +3 -0
  16. data/vendor/assets/javascripts/codemirror/addons/fold/brace-fold.js +3 -0
  17. data/vendor/assets/javascripts/codemirror/addons/fold/comment-fold.js +3 -0
  18. data/vendor/assets/javascripts/codemirror/addons/fold/foldcode.js +36 -8
  19. data/vendor/assets/javascripts/codemirror/addons/fold/foldgutter.js +3 -0
  20. data/vendor/assets/javascripts/codemirror/addons/fold/indent-fold.js +3 -0
  21. data/vendor/assets/javascripts/codemirror/addons/fold/markdown-fold.js +3 -0
  22. data/vendor/assets/javascripts/codemirror/addons/fold/xml-fold.js +4 -1
  23. data/vendor/assets/javascripts/codemirror/addons/hint/anyword-hint.js +3 -0
  24. data/vendor/assets/javascripts/codemirror/addons/hint/css-hint.js +3 -0
  25. data/vendor/assets/javascripts/codemirror/addons/hint/html-hint.js +3 -0
  26. data/vendor/assets/javascripts/codemirror/addons/hint/javascript-hint.js +7 -2
  27. data/vendor/assets/javascripts/codemirror/addons/hint/python-hint.js +3 -0
  28. data/vendor/assets/javascripts/codemirror/addons/hint/show-hint.js +74 -36
  29. data/vendor/assets/javascripts/codemirror/addons/hint/sql-hint.js +3 -0
  30. data/vendor/assets/javascripts/codemirror/addons/hint/xml-hint.js +3 -0
  31. data/vendor/assets/javascripts/codemirror/addons/lint/coffeescript-lint.js +3 -0
  32. data/vendor/assets/javascripts/codemirror/addons/lint/css-lint.js +3 -0
  33. data/vendor/assets/javascripts/codemirror/addons/lint/javascript-lint.js +3 -0
  34. data/vendor/assets/javascripts/codemirror/addons/lint/json-lint.js +3 -0
  35. data/vendor/assets/javascripts/codemirror/addons/lint/lint.js +3 -0
  36. data/vendor/assets/javascripts/codemirror/addons/lint/yaml-lint.js +3 -0
  37. data/vendor/assets/javascripts/codemirror/addons/merge/merge.js +3 -0
  38. data/vendor/assets/javascripts/codemirror/addons/mode/loadmode.js +3 -0
  39. data/vendor/assets/javascripts/codemirror/addons/mode/multiplex.js +3 -0
  40. data/vendor/assets/javascripts/codemirror/addons/mode/overlay.js +12 -3
  41. data/vendor/assets/javascripts/codemirror/addons/runmode/colorize.js +3 -0
  42. data/vendor/assets/javascripts/codemirror/addons/runmode/runmode-standalone.js +4 -1
  43. data/vendor/assets/javascripts/codemirror/addons/runmode/runmode.js +4 -1
  44. data/vendor/assets/javascripts/codemirror/addons/runmode/runmode.node.js +4 -1
  45. data/vendor/assets/javascripts/codemirror/addons/scroll/scrollpastend.js +3 -0
  46. data/vendor/assets/javascripts/codemirror/addons/search/match-highlighter.js +6 -2
  47. data/vendor/assets/javascripts/codemirror/addons/search/search.js +3 -0
  48. data/vendor/assets/javascripts/codemirror/addons/search/searchcursor.js +3 -0
  49. data/vendor/assets/javascripts/codemirror/addons/selection/active-line.js +3 -0
  50. data/vendor/assets/javascripts/codemirror/addons/selection/mark-selection.js +3 -0
  51. data/vendor/assets/javascripts/codemirror/addons/tern/tern.js +23 -16
  52. data/vendor/assets/javascripts/codemirror/addons/tern/worker.js +3 -0
  53. data/vendor/assets/javascripts/codemirror/addons/wrap/hardwrap.js +3 -0
  54. data/vendor/assets/javascripts/codemirror/keymaps/emacs.js +4 -7
  55. data/vendor/assets/javascripts/codemirror/keymaps/sublime.js +11 -8
  56. data/vendor/assets/javascripts/codemirror/keymaps/vim.js +92 -33
  57. data/vendor/assets/javascripts/codemirror/modes/apl.js +3 -0
  58. data/vendor/assets/javascripts/codemirror/modes/asterisk.js +3 -0
  59. data/vendor/assets/javascripts/codemirror/modes/clike.js +3 -0
  60. data/vendor/assets/javascripts/codemirror/modes/clojure.js +3 -0
  61. data/vendor/assets/javascripts/codemirror/modes/cobol.js +3 -0
  62. data/vendor/assets/javascripts/codemirror/modes/coffeescript.js +3 -0
  63. data/vendor/assets/javascripts/codemirror/modes/commonlisp.js +3 -0
  64. data/vendor/assets/javascripts/codemirror/modes/css.js +13 -14
  65. data/vendor/assets/javascripts/codemirror/modes/cypher.js +146 -0
  66. data/vendor/assets/javascripts/codemirror/modes/d.js +3 -0
  67. data/vendor/assets/javascripts/codemirror/modes/diff.js +3 -0
  68. data/vendor/assets/javascripts/codemirror/modes/django.js +3 -0
  69. data/vendor/assets/javascripts/codemirror/modes/dtd.js +3 -0
  70. data/vendor/assets/javascripts/codemirror/modes/dylan.js +15 -0
  71. data/vendor/assets/javascripts/codemirror/modes/ecl.js +3 -0
  72. data/vendor/assets/javascripts/codemirror/modes/eiffel.js +3 -0
  73. data/vendor/assets/javascripts/codemirror/modes/erlang.js +3 -0
  74. data/vendor/assets/javascripts/codemirror/modes/fortran.js +3 -0
  75. data/vendor/assets/javascripts/codemirror/modes/gas.js +3 -0
  76. data/vendor/assets/javascripts/codemirror/modes/gfm.js +9 -1
  77. data/vendor/assets/javascripts/codemirror/modes/gherkin.js +3 -0
  78. data/vendor/assets/javascripts/codemirror/modes/go.js +3 -0
  79. data/vendor/assets/javascripts/codemirror/modes/groovy.js +3 -0
  80. data/vendor/assets/javascripts/codemirror/modes/haml.js +3 -0
  81. data/vendor/assets/javascripts/codemirror/modes/haskell.js +3 -0
  82. data/vendor/assets/javascripts/codemirror/modes/haxe.js +5 -1
  83. data/vendor/assets/javascripts/codemirror/modes/htmlembedded.js +3 -0
  84. data/vendor/assets/javascripts/codemirror/modes/htmlmixed.js +3 -0
  85. data/vendor/assets/javascripts/codemirror/modes/http.js +3 -0
  86. data/vendor/assets/javascripts/codemirror/modes/jade.js +569 -81
  87. data/vendor/assets/javascripts/codemirror/modes/javascript.js +5 -0
  88. data/vendor/assets/javascripts/codemirror/modes/jinja2.js +3 -0
  89. data/vendor/assets/javascripts/codemirror/modes/julia.js +3 -0
  90. data/vendor/assets/javascripts/codemirror/modes/livescript.js +17 -17
  91. data/vendor/assets/javascripts/codemirror/modes/lua.js +3 -0
  92. data/vendor/assets/javascripts/codemirror/modes/markdown.js +5 -3
  93. data/vendor/assets/javascripts/codemirror/modes/mirc.js +3 -0
  94. data/vendor/assets/javascripts/codemirror/modes/mllike.js +3 -0
  95. data/vendor/assets/javascripts/codemirror/modes/nginx.js +3 -0
  96. data/vendor/assets/javascripts/codemirror/modes/ntriples.js +3 -0
  97. data/vendor/assets/javascripts/codemirror/modes/octave.js +3 -0
  98. data/vendor/assets/javascripts/codemirror/modes/pascal.js +3 -0
  99. data/vendor/assets/javascripts/codemirror/modes/pegjs.js +3 -0
  100. data/vendor/assets/javascripts/codemirror/modes/perl.js +5 -0
  101. data/vendor/assets/javascripts/codemirror/modes/php.js +5 -2
  102. data/vendor/assets/javascripts/codemirror/modes/pig.js +3 -0
  103. data/vendor/assets/javascripts/codemirror/modes/properties.js +3 -0
  104. data/vendor/assets/javascripts/codemirror/modes/puppet.js +3 -0
  105. data/vendor/assets/javascripts/codemirror/modes/python.js +284 -328
  106. data/vendor/assets/javascripts/codemirror/modes/q.js +3 -0
  107. data/vendor/assets/javascripts/codemirror/modes/r.js +3 -0
  108. data/vendor/assets/javascripts/codemirror/modes/rpm.js +3 -0
  109. data/vendor/assets/javascripts/codemirror/modes/rst.js +3 -0
  110. data/vendor/assets/javascripts/codemirror/modes/ruby.js +3 -0
  111. data/vendor/assets/javascripts/codemirror/modes/rust.js +3 -0
  112. data/vendor/assets/javascripts/codemirror/modes/sass.js +3 -0
  113. data/vendor/assets/javascripts/codemirror/modes/scheme.js +3 -0
  114. data/vendor/assets/javascripts/codemirror/modes/shell.js +9 -2
  115. data/vendor/assets/javascripts/codemirror/modes/sieve.js +3 -0
  116. data/vendor/assets/javascripts/codemirror/modes/smalltalk.js +3 -0
  117. data/vendor/assets/javascripts/codemirror/modes/smarty.js +3 -0
  118. data/vendor/assets/javascripts/codemirror/modes/smartymixed.js +3 -0
  119. data/vendor/assets/javascripts/codemirror/modes/solr.js +3 -0
  120. data/vendor/assets/javascripts/codemirror/modes/sparql.js +3 -0
  121. data/vendor/assets/javascripts/codemirror/modes/sql.js +3 -0
  122. data/vendor/assets/javascripts/codemirror/modes/stex.js +3 -0
  123. data/vendor/assets/javascripts/codemirror/modes/tcl.js +3 -0
  124. data/vendor/assets/javascripts/codemirror/modes/tiddlywiki.js +3 -0
  125. data/vendor/assets/javascripts/codemirror/modes/tiki.js +3 -0
  126. data/vendor/assets/javascripts/codemirror/modes/toml.js +3 -0
  127. data/vendor/assets/javascripts/codemirror/modes/turtle.js +3 -0
  128. data/vendor/assets/javascripts/codemirror/modes/vb.js +3 -0
  129. data/vendor/assets/javascripts/codemirror/modes/vbscript.js +3 -0
  130. data/vendor/assets/javascripts/codemirror/modes/velocity.js +3 -0
  131. data/vendor/assets/javascripts/codemirror/modes/verilog.js +3 -0
  132. data/vendor/assets/javascripts/codemirror/modes/xml.js +4 -1
  133. data/vendor/assets/javascripts/codemirror/modes/xquery.js +3 -0
  134. data/vendor/assets/javascripts/codemirror/modes/yaml.js +3 -0
  135. data/vendor/assets/javascripts/codemirror/modes/z80.js +3 -0
  136. data/vendor/assets/stylesheets/codemirror/addons/tern/tern.css +1 -0
  137. data/vendor/assets/stylesheets/codemirror/themes/neo.css +40 -0
  138. metadata +4 -2
@@ -1,3 +1,6 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
1
4
  (function(mod) {
2
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
3
6
  mod(require("../../lib/codemirror"));
@@ -1,3 +1,6 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
1
4
  (function(mod) {
2
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
3
6
  mod(require("../../lib/codemirror"));
@@ -1,3 +1,6 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
1
4
  // Open simple dialogs on top of an editor. Relies on dialog.css.
2
5
 
3
6
  (function(mod) {
@@ -1,3 +1,6 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
1
4
  (function(mod) {
2
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
3
6
  mod(require("../../lib/codemirror"));
@@ -1,3 +1,6 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
1
4
  (function(mod) {
2
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
3
6
  mod(require("../../lib/codemirror"));
@@ -1,3 +1,6 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
1
4
  (function(mod) {
2
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
3
6
  mod(require("../../lib/codemirror"));
@@ -34,15 +37,22 @@
34
37
  var minH = cm.display.scroller.offsetHeight + 30;
35
38
  for (var i = 0; i < val.length; i++) {
36
39
  var elt = document.createElement("div");
37
- var col, cls = null;
38
- if (typeof val[i] == "number") {
39
- col = val[i];
40
+ elt.className = "CodeMirror-ruler";
41
+ var col, cls = null, conf = val[i];
42
+ if (typeof conf == "number") {
43
+ col = conf;
40
44
  } else {
41
- col = val[i].column;
45
+ col = conf.column;
46
+ if (conf.className) elt.className = " " + conf.className;
47
+ if (conf.color) elt.style.borderColor = conf.color;
48
+ if (conf.lineStyle) elt.style.borderLeftStyle = conf.lineStyle;
49
+ if (conf.width) elt.style.borderLeftWidth = conf.width;
42
50
  cls = val[i].className;
43
51
  }
44
- elt.className = "CodeMirror-ruler" + (cls ? " " + cls : "");
45
- elt.style.cssText = "left: " + (left + col * cw) + "px; top: -50px; bottom: -20px; min-height: " + minH + "px";
52
+ elt.style.left = (left + col * cw) + "px";
53
+ elt.style.top = "-50px";
54
+ elt.style.bottom = "-20px";
55
+ elt.style.minHeight = minH + "px";
46
56
  cm.display.lineSpace.insertBefore(elt, cm.display.cursorDiv);
47
57
  }
48
58
  }
@@ -1,3 +1,6 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
1
4
  (function(mod) {
2
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
3
6
  mod(require("../../lib/codemirror"));
@@ -1,3 +1,6 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
1
4
  /**
2
5
  * Tag-closer extension for CodeMirror.
3
6
  *
@@ -55,6 +58,7 @@
55
58
  var pos = ranges[i].head, tok = cm.getTokenAt(pos);
56
59
  var inner = CodeMirror.innerMode(cm.getMode(), tok.state), state = inner.state;
57
60
  if (inner.mode.name != "xml" || !state.tagName) return CodeMirror.Pass;
61
+
58
62
  var opt = cm.getOption("autoCloseTags"), html = inner.mode.configuration == "html";
59
63
  var dontCloseTags = (typeof opt == "object" && opt.dontCloseTags) || (html && htmlDontClose);
60
64
  var indentTags = (typeof opt == "object" && opt.indentTags) || (html && htmlIndent);
@@ -68,8 +72,7 @@
68
72
  tok.type == "tag" && state.type == "closeTag" ||
69
73
  tok.string.indexOf("/") == (tok.string.length - 1) || // match something like <someTagName />
70
74
  dontCloseTags && indexOf(dontCloseTags, lowerTagName) > -1 ||
71
- CodeMirror.scanForClosingTag && CodeMirror.scanForClosingTag(cm, pos, tagName,
72
- Math.min(cm.lastLine() + 1, pos.line + 50)))
75
+ closingTagExists(cm, tagName, pos, state, true))
73
76
  return CodeMirror.Pass;
74
77
 
75
78
  var indent = indentTags && indexOf(indentTags, lowerTagName) > -1;
@@ -100,7 +103,8 @@
100
103
  var inner = CodeMirror.innerMode(cm.getMode(), tok.state), state = inner.state;
101
104
  if (tok.type == "string" || tok.string.charAt(0) != "<" ||
102
105
  tok.start != pos.ch - 1 || inner.mode.name != "xml" ||
103
- !state.context || !state.context.tagName)
106
+ !state.context || !state.context.tagName ||
107
+ closingTagExists(cm, state.context.tagName, pos, state))
104
108
  return CodeMirror.Pass;
105
109
  replacements[i] = "/" + state.context.tagName + ">";
106
110
  }
@@ -113,4 +117,25 @@
113
117
  if (collection[i] == elt) return i;
114
118
  return -1;
115
119
  }
120
+
121
+ // If xml-fold is loaded, we use its functionality to try and verify
122
+ // whether a given tag is actually unclosed.
123
+ function closingTagExists(cm, tagName, pos, state, newTag) {
124
+ if (!CodeMirror.scanForClosingTag) return false;
125
+ var end = Math.min(cm.lastLine() + 1, pos.line + 500);
126
+ var nextClose = CodeMirror.scanForClosingTag(cm, pos, null, end);
127
+ if (!nextClose || nextClose.tag != tagName) return false;
128
+ var cx = state.context;
129
+ // If the immediate wrapping context contains onCx instances of
130
+ // the same tag, a closing tag only exists if there are at least
131
+ // that many closing tags of that type following.
132
+ for (var onCx = newTag ? 1 : 0; cx && cx.tagName == tagName; cx = cx.prev) ++onCx;
133
+ pos = nextClose.to;
134
+ for (var i = 1; i < onCx; i++) {
135
+ var next = CodeMirror.scanForClosingTag(cm, pos, null, end);
136
+ if (!next || next.tag != tagName) return false;
137
+ pos = next.to;
138
+ }
139
+ return true;
140
+ }
116
141
  });
@@ -1,3 +1,6 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
1
4
  (function(mod) {
2
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
3
6
  mod(require("../../lib/codemirror"));
@@ -1,3 +1,6 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
1
4
  (function(mod) {
2
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
3
6
  mod(require("../../lib/codemirror"));
@@ -1,3 +1,6 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
1
4
  (function(mod) {
2
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
3
6
  mod(require("../../lib/codemirror"), require("../fold/xml-fold"));
@@ -1,3 +1,6 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
1
4
  (function(mod) {
2
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
3
6
  mod(require("../../lib/codemirror"));
@@ -1,3 +1,6 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
1
4
  (function(mod) {
2
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
3
6
  mod(require("../../lib/codemirror"));
@@ -1,3 +1,6 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
1
4
  (function(mod) {
2
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
3
6
  mod(require("../../lib/codemirror"));
@@ -1,3 +1,6 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
1
4
  (function(mod) {
2
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
3
6
  mod(require("../../lib/codemirror"));
@@ -9,10 +12,14 @@
9
12
  "use strict";
10
13
 
11
14
  function doFold(cm, pos, options, force) {
12
- var finder = options && (options.call ? options : options.rangeFinder);
13
- if (!finder) finder = CodeMirror.fold.auto;
15
+ if (options && options.call) {
16
+ var finder = options;
17
+ options = null;
18
+ } else {
19
+ var finder = getOption(cm, options, "rangeFinder");
20
+ }
14
21
  if (typeof pos == "number") pos = CodeMirror.Pos(pos, 0);
15
- var minSize = options && options.minFoldSize || 0;
22
+ var minSize = getOption(cm, options, "minFoldSize");
16
23
 
17
24
  function getRange(allowFolded) {
18
25
  var range = finder(cm, pos);
@@ -29,14 +36,17 @@
29
36
  }
30
37
 
31
38
  var range = getRange(true);
32
- if (options && options.scanUp) while (!range && pos.line > cm.firstLine()) {
39
+ if (getOption(cm, options, "scanUp")) while (!range && pos.line > cm.firstLine()) {
33
40
  pos = CodeMirror.Pos(pos.line - 1, 0);
34
41
  range = getRange(false);
35
42
  }
36
43
  if (!range || range.cleared || force === "unfold") return;
37
44
 
38
- var myWidget = makeWidget(options);
39
- CodeMirror.on(myWidget, "mousedown", function() { myRange.clear(); });
45
+ var myWidget = makeWidget(cm, options);
46
+ CodeMirror.on(myWidget, "mousedown", function(e) {
47
+ myRange.clear();
48
+ CodeMirror.e_preventDefault(e);
49
+ });
40
50
  var myRange = cm.markText(range.from, range.to, {
41
51
  replacedWith: myWidget,
42
52
  clearOnEnter: true,
@@ -48,8 +58,8 @@
48
58
  CodeMirror.signal(cm, "fold", cm, range.from, range.to);
49
59
  }
50
60
 
51
- function makeWidget(options) {
52
- var widget = (options && options.widget) || "\u2194";
61
+ function makeWidget(cm, options) {
62
+ var widget = getOption(cm, options, "widget");
53
63
  if (typeof widget == "string") {
54
64
  var text = document.createTextNode(widget);
55
65
  widget = document.createElement("span");
@@ -114,4 +124,22 @@
114
124
  if (cur) return cur;
115
125
  }
116
126
  });
127
+
128
+ var defaultOptions = {
129
+ rangeFinder: CodeMirror.fold.auto,
130
+ widget: "\u2194",
131
+ minFoldSize: 0,
132
+ scanUp: false
133
+ };
134
+
135
+ CodeMirror.defineOption("foldOptions", null);
136
+
137
+ function getOption(cm, options, name) {
138
+ if (options && options[name] !== undefined)
139
+ return options[name];
140
+ var editorOptions = cm.options.foldOptions;
141
+ if (editorOptions && editorOptions[name] !== undefined)
142
+ return editorOptions[name];
143
+ return defaultOptions[name];
144
+ }
117
145
  });
@@ -1,3 +1,6 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
1
4
  (function(mod) {
2
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
3
6
  mod(require("../../lib/codemirror"), require("./foldcode"));
@@ -1,3 +1,6 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
1
4
  (function(mod) {
2
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
3
6
  mod(require("../../lib/codemirror"));
@@ -1,3 +1,6 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
1
4
  (function(mod) {
2
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
3
6
  mod(require("../../lib/codemirror"));
@@ -1,3 +1,6 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
1
4
  (function(mod) {
2
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
3
6
  mod(require("../../lib/codemirror"));
@@ -173,6 +176,6 @@
173
176
  // Used by addon/edit/closetag.js
174
177
  CodeMirror.scanForClosingTag = function(cm, pos, name, end) {
175
178
  var iter = new Iter(cm, pos.line, pos.ch, end ? {from: 0, to: end} : null);
176
- return !!findMatchingClose(iter, name);
179
+ return findMatchingClose(iter, name);
177
180
  };
178
181
  });
@@ -1,3 +1,6 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
1
4
  (function(mod) {
2
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
3
6
  mod(require("../../lib/codemirror"));
@@ -1,3 +1,6 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
1
4
  (function(mod) {
2
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
3
6
  mod(require("../../lib/codemirror"), require("../../mode/css/css"));
@@ -1,3 +1,6 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
1
4
  (function(mod) {
2
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
3
6
  mod(require("../../lib/codemirror"));
@@ -1,3 +1,6 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
1
4
  (function(mod) {
2
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
3
6
  mod(require("../../lib/codemirror"));
@@ -108,7 +111,8 @@
108
111
  if (obj.type && obj.type.indexOf("variable") === 0) {
109
112
  if (options && options.additionalContext)
110
113
  base = options.additionalContext[obj.string];
111
- base = base || window[obj.string];
114
+ if (!options || options.useGlobalScope !== false)
115
+ base = base || window[obj.string];
112
116
  } else if (obj.type == "string") {
113
117
  base = "";
114
118
  } else if (obj.type == "atom") {
@@ -128,7 +132,8 @@
128
132
  // (reading into JS mode internals to get at the local and global variables)
129
133
  for (var v = token.state.localVars; v; v = v.next) maybeAdd(v.name);
130
134
  for (var v = token.state.globalVars; v; v = v.next) maybeAdd(v.name);
131
- gatherCompletions(window);
135
+ if (!options || options.useGlobalScope !== false)
136
+ gatherCompletions(window);
132
137
  forEach(keywords, maybeAdd);
133
138
  }
134
139
  return found;
@@ -1,3 +1,6 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
1
4
  (function(mod) {
2
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
3
6
  mod(require("../../lib/codemirror"));
@@ -1,3 +1,6 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
1
4
  (function(mod) {
2
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
3
6
  mod(require("../../lib/codemirror"));
@@ -11,28 +14,35 @@
11
14
  var HINT_ELEMENT_CLASS = "CodeMirror-hint";
12
15
  var ACTIVE_HINT_ELEMENT_CLASS = "CodeMirror-hint-active";
13
16
 
17
+ // This is the old interface, kept around for now to stay
18
+ // backwards-compatible.
14
19
  CodeMirror.showHint = function(cm, getHints, options) {
20
+ if (!getHints) return cm.showHint(options);
21
+ if (options && options.async) getHints.async = true;
22
+ var newOpts = {hint: getHints};
23
+ if (options) for (var prop in options) newOpts[prop] = options[prop];
24
+ return cm.showHint(newOpts);
25
+ };
26
+
27
+ CodeMirror.defineExtension("showHint", function(options) {
15
28
  // We want a single cursor position.
16
- if (cm.listSelections().length > 1 || cm.somethingSelected()) return;
17
- if (getHints == null) {
18
- if (options && options.async) return;
19
- else getHints = CodeMirror.hint.auto;
20
- }
29
+ if (this.listSelections().length > 1 || this.somethingSelected()) return;
21
30
 
22
- if (cm.state.completionActive) cm.state.completionActive.close();
31
+ if (this.state.completionActive) this.state.completionActive.close();
32
+ var completion = this.state.completionActive = new Completion(this, options);
33
+ var getHints = completion.options.hint;
34
+ if (!getHints) return;
23
35
 
24
- var completion = cm.state.completionActive = new Completion(cm, getHints, options || {});
25
- CodeMirror.signal(cm, "startCompletion", cm);
26
- if (completion.options.async)
27
- getHints(cm, function(hints) { completion.showHints(hints); }, completion.options);
36
+ CodeMirror.signal(this, "startCompletion", this);
37
+ if (getHints.async)
38
+ getHints(this, function(hints) { completion.showHints(hints); }, completion.options);
28
39
  else
29
- return completion.showHints(getHints(cm, completion.options));
30
- };
40
+ return completion.showHints(getHints(this, completion.options));
41
+ });
31
42
 
32
- function Completion(cm, getHints, options) {
43
+ function Completion(cm, options) {
33
44
  this.cm = cm;
34
- this.getHints = getHints;
35
- this.options = options;
45
+ this.options = this.buildOptions(options);
36
46
  this.widget = this.onClose = null;
37
47
  }
38
48
 
@@ -62,7 +72,7 @@
62
72
  showHints: function(data) {
63
73
  if (!data || !data.list.length || !this.active()) return this.close();
64
74
 
65
- if (this.options.completeSingle != false && data.list.length == 1)
75
+ if (this.options.completeSingle && data.list.length == 1)
66
76
  this.pick(data, 0);
67
77
  else
68
78
  this.showWidget(data);
@@ -73,7 +83,7 @@
73
83
  CodeMirror.signal(data, "shown");
74
84
 
75
85
  var debounce = 0, completion = this, finished;
76
- var closeOn = this.options.closeCharacters || /[\s()\[\]{};:>,]/;
86
+ var closeOn = this.options.closeCharacters;
77
87
  var startPos = this.cm.getCursor(), startLen = this.cm.getLine(startPos.line).length;
78
88
 
79
89
  var requestAnimationFrame = window.requestAnimationFrame || function(fn) {
@@ -92,10 +102,11 @@
92
102
  function update() {
93
103
  if (finished) return;
94
104
  CodeMirror.signal(data, "update");
95
- if (completion.options.async)
96
- completion.getHints(completion.cm, finishUpdate, completion.options);
105
+ var getHints = completion.options.hint;
106
+ if (getHints.async)
107
+ getHints(completion.cm, finishUpdate, completion.options);
97
108
  else
98
- finishUpdate(completion.getHints(completion.cm, completion.options));
109
+ finishUpdate(getHints(completion.cm, completion.options));
99
110
  }
100
111
  function finishUpdate(data_) {
101
112
  data = data_;
@@ -126,6 +137,17 @@
126
137
  }
127
138
  this.cm.on("cursorActivity", activity);
128
139
  this.onClose = done;
140
+ },
141
+
142
+ buildOptions: function(options) {
143
+ var editor = this.cm.options.hintOptions;
144
+ var out = {};
145
+ for (var prop in defaultOptions) out[prop] = defaultOptions[prop];
146
+ if (editor) for (var prop in editor)
147
+ if (editor[prop] !== undefined) out[prop] = editor[prop];
148
+ if (options) for (var prop in options)
149
+ if (options[prop] !== undefined) out[prop] = options[prop];
150
+ return out;
129
151
  }
130
152
  };
131
153
 
@@ -134,7 +156,7 @@
134
156
  else return completion.text;
135
157
  }
136
158
 
137
- function buildKeyMap(options, handle) {
159
+ function buildKeyMap(completion, handle) {
138
160
  var baseMap = {
139
161
  Up: function() {handle.moveFocus(-1);},
140
162
  Down: function() {handle.moveFocus(1);},
@@ -146,7 +168,8 @@
146
168
  Tab: handle.pick,
147
169
  Esc: handle.close
148
170
  };
149
- var ourMap = options.customKeys ? {} : baseMap;
171
+ var custom = completion.options.customKeys;
172
+ var ourMap = custom ? {} : baseMap;
150
173
  function addBinding(key, val) {
151
174
  var bound;
152
175
  if (typeof val != "string")
@@ -158,12 +181,13 @@
158
181
  bound = val;
159
182
  ourMap[key] = bound;
160
183
  }
161
- if (options.customKeys)
162
- for (var key in options.customKeys) if (options.customKeys.hasOwnProperty(key))
163
- addBinding(key, options.customKeys[key]);
164
- if (options.extraKeys)
165
- for (var key in options.extraKeys) if (options.extraKeys.hasOwnProperty(key))
166
- addBinding(key, options.extraKeys[key]);
184
+ if (custom)
185
+ for (var key in custom) if (custom.hasOwnProperty(key))
186
+ addBinding(key, custom[key]);
187
+ var extra = completion.options.extraKeys;
188
+ if (extra)
189
+ for (var key in extra) if (extra.hasOwnProperty(key))
190
+ addBinding(key, extra[key]);
167
191
  return ourMap;
168
192
  }
169
193
 
@@ -177,11 +201,11 @@
177
201
  function Widget(completion, data) {
178
202
  this.completion = completion;
179
203
  this.data = data;
180
- var widget = this, cm = completion.cm, options = completion.options;
204
+ var widget = this, cm = completion.cm;
181
205
 
182
206
  var hints = this.hints = document.createElement("ul");
183
207
  hints.className = "CodeMirror-hints";
184
- this.selectedHint = options.getDefaultSelection ? options.getDefaultSelection(cm,options,data) : 0;
208
+ this.selectedHint = data.selectedHint || 0;
185
209
 
186
210
  var completions = data.list;
187
211
  for (var i = 0; i < completions.length; ++i) {
@@ -194,14 +218,14 @@
194
218
  elt.hintId = i;
195
219
  }
196
220
 
197
- var pos = cm.cursorCoords(options.alignWithWord !== false ? data.from : null);
221
+ var pos = cm.cursorCoords(completion.options.alignWithWord ? data.from : null);
198
222
  var left = pos.left, top = pos.bottom, below = true;
199
223
  hints.style.left = left + "px";
200
224
  hints.style.top = top + "px";
201
225
  // If we're at the edge of the screen, then we want the menu to appear on the left of the cursor.
202
226
  var winW = window.innerWidth || Math.max(document.body.offsetWidth, document.documentElement.offsetWidth);
203
227
  var winH = window.innerHeight || Math.max(document.body.offsetHeight, document.documentElement.offsetHeight);
204
- (options.container || document.body).appendChild(hints);
228
+ (completion.options.container || document.body).appendChild(hints);
205
229
  var box = hints.getBoundingClientRect(), overlapY = box.bottom - winH;
206
230
  if (overlapY > 0) {
207
231
  var height = box.bottom - box.top, curTop = box.top - (pos.bottom - pos.top);
@@ -228,7 +252,7 @@
228
252
  hints.style.left = (left = pos.left - overlapX) + "px";
229
253
  }
230
254
 
231
- cm.addKeyMap(this.keyMap = buildKeyMap(options, {
255
+ cm.addKeyMap(this.keyMap = buildKeyMap(completion, {
232
256
  moveFocus: function(n, avoidWrap) { widget.changeActive(widget.selectedHint + n, avoidWrap); },
233
257
  setFocus: function(n) { widget.changeActive(n); },
234
258
  menuSize: function() { return widget.screenAmount(); },
@@ -238,7 +262,7 @@
238
262
  data: data
239
263
  }));
240
264
 
241
- if (options.closeOnUnfocus !== false) {
265
+ if (completion.options.closeOnUnfocus) {
242
266
  var closingOnBlur;
243
267
  cm.on("blur", this.onBlur = function() { closingOnBlur = setTimeout(function() { completion.close(); }, 100); });
244
268
  cm.on("focus", this.onFocus = function() { clearTimeout(closingOnBlur); });
@@ -264,7 +288,7 @@
264
288
  var t = getHintElement(hints, e.target || e.srcElement);
265
289
  if (t && t.hintId != null) {
266
290
  widget.changeActive(t.hintId);
267
- if (options.completeOnSingleClick) widget.pick();
291
+ if (completion.options.completeOnSingleClick) widget.pick();
268
292
  }
269
293
  });
270
294
 
@@ -284,7 +308,7 @@
284
308
  this.completion.cm.removeKeyMap(this.keyMap);
285
309
 
286
310
  var cm = this.completion.cm;
287
- if (this.completion.options.closeOnUnfocus !== false) {
311
+ if (this.completion.options.closeOnUnfocus) {
288
312
  cm.off("blur", this.onBlur);
289
313
  cm.off("focus", this.onFocus);
290
314
  }
@@ -348,4 +372,18 @@
348
372
  });
349
373
 
350
374
  CodeMirror.commands.autocomplete = CodeMirror.showHint;
375
+
376
+ var defaultOptions = {
377
+ hint: CodeMirror.hint.auto,
378
+ completeSingle: true,
379
+ alignWithWord: true,
380
+ closeCharacters: /[\s()\[\]{};:>,]/,
381
+ closeOnUnfocus: true,
382
+ completeOnSingleClick: false,
383
+ container: null,
384
+ customKeys: null,
385
+ extraKeys: null
386
+ };
387
+
388
+ CodeMirror.defineOption("hintOptions", null);
351
389
  });