codemirror-rails 3.24 → 4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +4 -4
  2. data/lib/codemirror/rails/version.rb +2 -2
  3. data/vendor/assets/javascripts/codemirror.js +3001 -1798
  4. data/vendor/assets/javascripts/codemirror/addons/comment/comment.js +24 -4
  5. data/vendor/assets/javascripts/codemirror/addons/comment/continuecomment.js +47 -32
  6. data/vendor/assets/javascripts/codemirror/addons/dialog/dialog.js +9 -2
  7. data/vendor/assets/javascripts/codemirror/addons/display/fullscreen.js +9 -2
  8. data/vendor/assets/javascripts/codemirror/addons/display/placeholder.js +9 -2
  9. data/vendor/assets/javascripts/codemirror/addons/display/rulers.js +9 -2
  10. data/vendor/assets/javascripts/codemirror/addons/edit/closebrackets.js +76 -37
  11. data/vendor/assets/javascripts/codemirror/addons/edit/closetag.js +59 -37
  12. data/vendor/assets/javascripts/codemirror/addons/edit/continuelist.js +25 -17
  13. data/vendor/assets/javascripts/codemirror/addons/edit/matchbrackets.js +67 -46
  14. data/vendor/assets/javascripts/codemirror/addons/edit/matchtags.js +10 -3
  15. data/vendor/assets/javascripts/codemirror/addons/edit/trailingspace.js +23 -14
  16. data/vendor/assets/javascripts/codemirror/addons/fold/brace-fold.js +12 -3
  17. data/vendor/assets/javascripts/codemirror/addons/fold/comment-fold.js +12 -0
  18. data/vendor/assets/javascripts/codemirror/addons/fold/foldcode.js +28 -3
  19. data/vendor/assets/javascripts/codemirror/addons/fold/foldgutter.js +9 -2
  20. data/vendor/assets/javascripts/codemirror/addons/fold/indent-fold.js +12 -1
  21. data/vendor/assets/javascripts/codemirror/addons/fold/markdown-fold.js +12 -0
  22. data/vendor/assets/javascripts/codemirror/addons/fold/xml-fold.js +9 -4
  23. data/vendor/assets/javascripts/codemirror/addons/hint/anyword-hint.js +9 -2
  24. data/vendor/assets/javascripts/codemirror/addons/hint/css-hint.js +10 -3
  25. data/vendor/assets/javascripts/codemirror/addons/hint/html-hint.js +11 -3
  26. data/vendor/assets/javascripts/codemirror/addons/hint/javascript-hint.js +9 -4
  27. data/vendor/assets/javascripts/codemirror/addons/hint/python-hint.js +11 -3
  28. data/vendor/assets/javascripts/codemirror/addons/hint/show-hint.js +10 -4
  29. data/vendor/assets/javascripts/codemirror/addons/hint/sql-hint.js +9 -2
  30. data/vendor/assets/javascripts/codemirror/addons/hint/xml-hint.js +22 -34
  31. data/vendor/assets/javascripts/codemirror/addons/lint/coffeescript-lint.js +12 -1
  32. data/vendor/assets/javascripts/codemirror/addons/lint/css-lint.js +12 -1
  33. data/vendor/assets/javascripts/codemirror/addons/lint/javascript-lint.js +9 -4
  34. data/vendor/assets/javascripts/codemirror/addons/lint/json-lint.js +12 -1
  35. data/vendor/assets/javascripts/codemirror/addons/lint/lint.js +12 -8
  36. data/vendor/assets/javascripts/codemirror/addons/lint/yaml-lint.js +12 -1
  37. data/vendor/assets/javascripts/codemirror/addons/merge/merge.js +18 -16
  38. data/vendor/assets/javascripts/codemirror/addons/mode/loadmode.js +9 -2
  39. data/vendor/assets/javascripts/codemirror/addons/mode/multiplex.js +12 -0
  40. data/vendor/assets/javascripts/codemirror/addons/mode/overlay.js +15 -10
  41. data/vendor/assets/javascripts/codemirror/addons/runmode/colorize.js +11 -3
  42. data/vendor/assets/javascripts/codemirror/addons/runmode/runmode-standalone.js +0 -2
  43. data/vendor/assets/javascripts/codemirror/addons/runmode/runmode.js +12 -0
  44. data/vendor/assets/javascripts/codemirror/addons/runmode/runmode.node.js +4 -0
  45. data/vendor/assets/javascripts/codemirror/addons/scroll/scrollpastend.js +9 -2
  46. data/vendor/assets/javascripts/codemirror/addons/search/match-highlighter.js +12 -3
  47. data/vendor/assets/javascripts/codemirror/addons/search/search.js +24 -16
  48. data/vendor/assets/javascripts/codemirror/addons/search/searchcursor.js +21 -2
  49. data/vendor/assets/javascripts/codemirror/addons/selection/active-line.js +38 -17
  50. data/vendor/assets/javascripts/codemirror/addons/selection/mark-selection.js +16 -9
  51. data/vendor/assets/javascripts/codemirror/addons/tern/tern.js +33 -5
  52. data/vendor/assets/javascripts/codemirror/addons/wrap/hardwrap.js +27 -2
  53. data/vendor/assets/javascripts/codemirror/keymaps/emacs.js +12 -5
  54. data/vendor/assets/javascripts/codemirror/keymaps/sublime.js +505 -0
  55. data/vendor/assets/javascripts/codemirror/keymaps/vim.js +138 -179
  56. data/vendor/assets/javascripts/codemirror/modes/apl.js +12 -0
  57. data/vendor/assets/javascripts/codemirror/modes/asterisk.js +12 -0
  58. data/vendor/assets/javascripts/codemirror/modes/clike.js +15 -4
  59. data/vendor/assets/javascripts/codemirror/modes/clojure.js +13 -0
  60. data/vendor/assets/javascripts/codemirror/modes/cobol.js +12 -0
  61. data/vendor/assets/javascripts/codemirror/modes/coffeescript.js +12 -0
  62. data/vendor/assets/javascripts/codemirror/modes/commonlisp.js +12 -0
  63. data/vendor/assets/javascripts/codemirror/modes/css.js +18 -27
  64. data/vendor/assets/javascripts/codemirror/modes/d.js +12 -2
  65. data/vendor/assets/javascripts/codemirror/modes/diff.js +12 -0
  66. data/vendor/assets/javascripts/codemirror/modes/dtd.js +12 -0
  67. data/vendor/assets/javascripts/codemirror/modes/ecl.js +12 -0
  68. data/vendor/assets/javascripts/codemirror/modes/eiffel.js +12 -0
  69. data/vendor/assets/javascripts/codemirror/modes/erlang.js +13 -1
  70. data/vendor/assets/javascripts/codemirror/modes/fortran.js +12 -0
  71. data/vendor/assets/javascripts/codemirror/modes/gas.js +12 -0
  72. data/vendor/assets/javascripts/codemirror/modes/gfm.js +12 -0
  73. data/vendor/assets/javascripts/codemirror/modes/gherkin.js +12 -0
  74. data/vendor/assets/javascripts/codemirror/modes/go.js +12 -1
  75. data/vendor/assets/javascripts/codemirror/modes/groovy.js +12 -0
  76. data/vendor/assets/javascripts/codemirror/modes/haml.js +12 -0
  77. data/vendor/assets/javascripts/codemirror/modes/haskell.js +12 -0
  78. data/vendor/assets/javascripts/codemirror/modes/haxe.js +18 -9
  79. data/vendor/assets/javascripts/codemirror/modes/htmlembedded.js +12 -0
  80. data/vendor/assets/javascripts/codemirror/modes/htmlmixed.js +12 -0
  81. data/vendor/assets/javascripts/codemirror/modes/http.js +12 -0
  82. data/vendor/assets/javascripts/codemirror/modes/jade.js +12 -0
  83. data/vendor/assets/javascripts/codemirror/modes/javascript.js +23 -16
  84. data/vendor/assets/javascripts/codemirror/modes/jinja2.js +53 -118
  85. data/vendor/assets/javascripts/codemirror/modes/julia.js +12 -0
  86. data/vendor/assets/javascripts/codemirror/modes/livescript.js +17 -4
  87. data/vendor/assets/javascripts/codemirror/modes/lua.js +12 -0
  88. data/vendor/assets/javascripts/codemirror/modes/markdown.js +12 -0
  89. data/vendor/assets/javascripts/codemirror/modes/mirc.js +13 -0
  90. data/vendor/assets/javascripts/codemirror/modes/mllike.js +12 -1
  91. data/vendor/assets/javascripts/codemirror/modes/nginx.js +12 -0
  92. data/vendor/assets/javascripts/codemirror/modes/ntriples.js +13 -0
  93. data/vendor/assets/javascripts/codemirror/modes/octave.js +12 -0
  94. data/vendor/assets/javascripts/codemirror/modes/pascal.js +12 -0
  95. data/vendor/assets/javascripts/codemirror/modes/pegjs.js +12 -0
  96. data/vendor/assets/javascripts/codemirror/modes/perl.js +84 -73
  97. data/vendor/assets/javascripts/codemirror/modes/php.js +20 -101
  98. data/vendor/assets/javascripts/codemirror/modes/pig.js +12 -0
  99. data/vendor/assets/javascripts/codemirror/modes/properties.js +12 -0
  100. data/vendor/assets/javascripts/codemirror/modes/puppet.js +13 -0
  101. data/vendor/assets/javascripts/codemirror/modes/python.js +21 -11
  102. data/vendor/assets/javascripts/codemirror/modes/q.js +12 -0
  103. data/vendor/assets/javascripts/codemirror/modes/r.js +13 -3
  104. data/vendor/assets/javascripts/codemirror/modes/{rpm-spec.js → rpm.js} +34 -2
  105. data/vendor/assets/javascripts/codemirror/modes/rst.js +12 -0
  106. data/vendor/assets/javascripts/codemirror/modes/ruby.js +11 -0
  107. data/vendor/assets/javascripts/codemirror/modes/rust.js +12 -0
  108. data/vendor/assets/javascripts/codemirror/modes/sass.js +12 -0
  109. data/vendor/assets/javascripts/codemirror/modes/scheme.js +13 -0
  110. data/vendor/assets/javascripts/codemirror/modes/shell.js +12 -0
  111. data/vendor/assets/javascripts/codemirror/modes/sieve.js +11 -4
  112. data/vendor/assets/javascripts/codemirror/modes/smalltalk.js +12 -0
  113. data/vendor/assets/javascripts/codemirror/modes/smarty.js +13 -0
  114. data/vendor/assets/javascripts/codemirror/modes/smartymixed.js +14 -2
  115. data/vendor/assets/javascripts/codemirror/modes/solr.js +12 -0
  116. data/vendor/assets/javascripts/codemirror/modes/sparql.js +12 -0
  117. data/vendor/assets/javascripts/codemirror/modes/sql.js +12 -0
  118. data/vendor/assets/javascripts/codemirror/modes/stex.js +12 -0
  119. data/vendor/assets/javascripts/codemirror/modes/tcl.js +13 -0
  120. data/vendor/assets/javascripts/codemirror/modes/tiddlywiki.js +13 -0
  121. data/vendor/assets/javascripts/codemirror/modes/tiki.js +12 -0
  122. data/vendor/assets/javascripts/codemirror/modes/toml.js +12 -0
  123. data/vendor/assets/javascripts/codemirror/modes/turtle.js +12 -0
  124. data/vendor/assets/javascripts/codemirror/modes/vb.js +12 -0
  125. data/vendor/assets/javascripts/codemirror/modes/vbscript.js +13 -0
  126. data/vendor/assets/javascripts/codemirror/modes/velocity.js +12 -0
  127. data/vendor/assets/javascripts/codemirror/modes/verilog.js +89 -236
  128. data/vendor/assets/javascripts/codemirror/modes/xml.js +41 -60
  129. data/vendor/assets/javascripts/codemirror/modes/xquery.js +12 -0
  130. data/vendor/assets/javascripts/codemirror/modes/yaml.js +12 -0
  131. data/vendor/assets/javascripts/codemirror/modes/z80.js +12 -0
  132. data/vendor/assets/stylesheets/codemirror.css +15 -10
  133. data/vendor/assets/stylesheets/codemirror/themes/ambiance.css +1 -0
  134. data/vendor/assets/stylesheets/codemirror/themes/lesser-dark.css +4 -0
  135. data/vendor/assets/stylesheets/codemirror/themes/mdn-like.css +1 -1
  136. data/vendor/assets/stylesheets/codemirror/themes/pastel-on-dark.css +1 -0
  137. data/vendor/assets/stylesheets/codemirror/themes/rubyblue.css +2 -0
  138. data/vendor/assets/stylesheets/codemirror/themes/solarized.css +17 -3
  139. metadata +20 -25
  140. data/vendor/assets/javascripts/codemirror/keymaps/extra.js +0 -43
  141. data/vendor/assets/javascripts/codemirror/modes/django.js +0 -55
  142. data/vendor/assets/javascripts/codemirror/modes/dylan.js +0 -284
  143. data/vendor/assets/javascripts/codemirror/modes/less.js +0 -347
  144. data/vendor/assets/javascripts/codemirror/modes/rpm-changes.js +0 -19
  145. data/vendor/assets/stylesheets/codemirror/modes/rpm-spec.css +0 -5
@@ -1,4 +1,11 @@
1
- (function() {
1
+ (function(mod) {
2
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
3
+ mod(require("../../lib/codemirror"));
4
+ else if (typeof define == "function" && define.amd) // AMD
5
+ define(["../../lib/codemirror"], mod);
6
+ else // Plain browser env
7
+ mod(CodeMirror);
8
+ })(function(CodeMirror) {
2
9
  "use strict";
3
10
 
4
11
  var noOptions = {};
@@ -11,8 +18,21 @@
11
18
  }
12
19
 
13
20
  CodeMirror.commands.toggleComment = function(cm) {
14
- var from = cm.getCursor("start"), to = cm.getCursor("end");
15
- cm.uncomment(from, to) || cm.lineComment(from, to);
21
+ var minLine = Infinity, ranges = cm.listSelections(), mode = null;
22
+ for (var i = ranges.length - 1; i >= 0; i--) {
23
+ var from = ranges[i].from(), to = ranges[i].to();
24
+ if (from.line >= minLine) continue;
25
+ if (to.line >= minLine) to = Pos(minLine, 0);
26
+ minLine = from.line;
27
+ if (mode == null) {
28
+ if (cm.uncomment(from, to)) mode = "un";
29
+ else { cm.lineComment(from, to); mode = "line"; }
30
+ } else if (mode == "un") {
31
+ cm.uncomment(from, to);
32
+ } else {
33
+ cm.lineComment(from, to);
34
+ }
35
+ }
16
36
  };
17
37
 
18
38
  CodeMirror.defineExtension("lineComment", function(from, to, options) {
@@ -146,4 +166,4 @@
146
166
  });
147
167
  return true;
148
168
  });
149
- })();
169
+ });
@@ -1,46 +1,61 @@
1
- (function() {
1
+ (function(mod) {
2
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
3
+ mod(require("../../lib/codemirror"));
4
+ else if (typeof define == "function" && define.amd) // AMD
5
+ define(["../../lib/codemirror"], mod);
6
+ else // Plain browser env
7
+ mod(CodeMirror);
8
+ })(function(CodeMirror) {
2
9
  var modes = ["clike", "css", "javascript"];
3
10
 
4
11
  for (var i = 0; i < modes.length; ++i)
5
12
  CodeMirror.extendMode(modes[i], {blockCommentContinue: " * "});
6
13
 
7
14
  function continueComment(cm) {
8
- var pos = cm.getCursor(), token = cm.getTokenAt(pos);
9
- if (token.type != "comment" || cm.getOption("disableInput")) return CodeMirror.Pass;
10
- var mode = CodeMirror.innerMode(cm.getMode(), token.state).mode;
15
+ if (cm.getOption("disableInput")) return CodeMirror.Pass;
16
+ var ranges = cm.listSelections(), mode, inserts = [];
17
+ for (var i = 0; i < ranges.length; i++) {
18
+ var pos = ranges[i].head, token = cm.getTokenAt(pos);
19
+ if (token.type != "comment") return CodeMirror.Pass;
20
+ var modeHere = CodeMirror.innerMode(cm.getMode(), token.state).mode;
21
+ if (!mode) mode = modeHere;
22
+ else if (mode != modeHere) return CodeMirror.Pass;
11
23
 
12
- var insert;
13
- if (mode.blockCommentStart && mode.blockCommentContinue) {
14
- var end = token.string.indexOf(mode.blockCommentEnd);
15
- var full = cm.getRange(CodeMirror.Pos(pos.line, 0), CodeMirror.Pos(pos.line, token.end)), found;
16
- if (end != -1 && end == token.string.length - mode.blockCommentEnd.length && pos.ch >= end) {
17
- // Comment ended, don't continue it
18
- } else if (token.string.indexOf(mode.blockCommentStart) == 0) {
19
- insert = full.slice(0, token.start);
20
- if (!/^\s*$/.test(insert)) {
21
- insert = "";
22
- for (var i = 0; i < token.start; ++i) insert += " ";
24
+ var insert = null;
25
+ if (mode.blockCommentStart && mode.blockCommentContinue) {
26
+ var end = token.string.indexOf(mode.blockCommentEnd);
27
+ var full = cm.getRange(CodeMirror.Pos(pos.line, 0), CodeMirror.Pos(pos.line, token.end)), found;
28
+ if (end != -1 && end == token.string.length - mode.blockCommentEnd.length && pos.ch >= end) {
29
+ // Comment ended, don't continue it
30
+ } else if (token.string.indexOf(mode.blockCommentStart) == 0) {
31
+ insert = full.slice(0, token.start);
32
+ if (!/^\s*$/.test(insert)) {
33
+ insert = "";
34
+ for (var j = 0; j < token.start; ++j) insert += " ";
35
+ }
36
+ } else if ((found = full.indexOf(mode.blockCommentContinue)) != -1 &&
37
+ found + mode.blockCommentContinue.length > token.start &&
38
+ /^\s*$/.test(full.slice(0, found))) {
39
+ insert = full.slice(0, found);
23
40
  }
24
- } else if ((found = full.indexOf(mode.blockCommentContinue)) != -1 &&
25
- found + mode.blockCommentContinue.length > token.start &&
26
- /^\s*$/.test(full.slice(0, found))) {
27
- insert = full.slice(0, found);
41
+ if (insert != null) insert += mode.blockCommentContinue;
28
42
  }
29
- if (insert != null) insert += mode.blockCommentContinue;
30
- }
31
- if (insert == null && mode.lineComment && continueLineCommentEnabled(cm)) {
32
- var line = cm.getLine(pos.line), found = line.indexOf(mode.lineComment);
33
- if (found > -1) {
34
- insert = line.slice(0, found);
35
- if (/\S/.test(insert)) insert = null;
36
- else insert += mode.lineComment + line.slice(found + mode.lineComment.length).match(/^\s*/)[0];
43
+ if (insert == null && mode.lineComment && continueLineCommentEnabled(cm)) {
44
+ var line = cm.getLine(pos.line), found = line.indexOf(mode.lineComment);
45
+ if (found > -1) {
46
+ insert = line.slice(0, found);
47
+ if (/\S/.test(insert)) insert = null;
48
+ else insert += mode.lineComment + line.slice(found + mode.lineComment.length).match(/^\s*/)[0];
49
+ }
37
50
  }
51
+ if (insert == null) return CodeMirror.Pass;
52
+ inserts[i] = "\n" + insert;
38
53
  }
39
54
 
40
- if (insert != null)
41
- cm.replaceSelection("\n" + insert, "end");
42
- else
43
- return CodeMirror.Pass;
55
+ cm.operation(function() {
56
+ for (var i = ranges.length - 1; i >= 0; i--)
57
+ cm.replaceRange(inserts[i], ranges[i].from(), ranges[i].to(), "+insert");
58
+ });
44
59
  }
45
60
 
46
61
  function continueLineCommentEnabled(cm) {
@@ -64,4 +79,4 @@
64
79
  cm.addKeyMap(map);
65
80
  }
66
81
  });
67
- })();
82
+ });
@@ -1,6 +1,13 @@
1
1
  // Open simple dialogs on top of an editor. Relies on dialog.css.
2
2
 
3
- (function() {
3
+ (function(mod) {
4
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
5
+ mod(require("../../lib/codemirror"));
6
+ else if (typeof define == "function" && define.amd) // AMD
7
+ define(["../../lib/codemirror"], mod);
8
+ else // Plain browser env
9
+ mod(CodeMirror);
10
+ })(function(CodeMirror) {
4
11
  function dialogDiv(cm, template, bottom) {
5
12
  var wrap = cm.getWrapperElement();
6
13
  var dialog;
@@ -120,4 +127,4 @@
120
127
  if (duration)
121
128
  doneTimer = setTimeout(close, options.duration);
122
129
  });
123
- })();
130
+ });
@@ -1,4 +1,11 @@
1
- (function() {
1
+ (function(mod) {
2
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
3
+ mod(require("../../lib/codemirror"));
4
+ else if (typeof define == "function" && define.amd) // AMD
5
+ define(["../../lib/codemirror"], mod);
6
+ else // Plain browser env
7
+ mod(CodeMirror);
8
+ })(function(CodeMirror) {
2
9
  "use strict";
3
10
 
4
11
  CodeMirror.defineOption("fullScreen", false, function(cm, val, old) {
@@ -28,4 +35,4 @@
28
35
  window.scrollTo(info.scrollLeft, info.scrollTop);
29
36
  cm.refresh();
30
37
  }
31
- })();
38
+ });
@@ -1,4 +1,11 @@
1
- (function() {
1
+ (function(mod) {
2
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
3
+ mod(require("../../lib/codemirror"));
4
+ else if (typeof define == "function" && define.amd) // AMD
5
+ define(["../../lib/codemirror"], mod);
6
+ else // Plain browser env
7
+ mod(CodeMirror);
8
+ })(function(CodeMirror) {
2
9
  CodeMirror.defineOption("placeholder", "", function(cm, val, old) {
3
10
  var prev = old && old != CodeMirror.Init;
4
11
  if (val && !prev) {
@@ -45,4 +52,4 @@
45
52
  function isEmpty(cm) {
46
53
  return (cm.lineCount() === 1) && (cm.getLine(0) === "");
47
54
  }
48
- })();
55
+ });
@@ -1,4 +1,11 @@
1
- (function() {
1
+ (function(mod) {
2
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
3
+ mod(require("../../lib/codemirror"));
4
+ else if (typeof define == "function" && define.amd) // AMD
5
+ define(["../../lib/codemirror"], mod);
6
+ else // Plain browser env
7
+ mod(CodeMirror);
8
+ })(function(CodeMirror) {
2
9
  "use strict";
3
10
 
4
11
  CodeMirror.defineOption("rulers", false, function(cm, val, old) {
@@ -44,4 +51,4 @@
44
51
  clearRulers(cm);
45
52
  setRulers(cm);
46
53
  }
47
- })();
54
+ });
@@ -1,4 +1,11 @@
1
- (function() {
1
+ (function(mod) {
2
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
3
+ mod(require("../../lib/codemirror"));
4
+ else if (typeof define == "function" && define.amd) // AMD
5
+ define(["../../lib/codemirror"], mod);
6
+ else // Plain browser env
7
+ mod(CodeMirror);
8
+ })(function(CodeMirror) {
2
9
  var DEFAULT_BRACKETS = "()[]{}''\"\"";
3
10
  var DEFAULT_EXPLODE_ON_ENTER = "[]{}";
4
11
  var SPACE_CHAR_REGEX = /\s/;
@@ -28,57 +35,89 @@
28
35
  var map = {
29
36
  name : "autoCloseBrackets",
30
37
  Backspace: function(cm) {
31
- if (cm.somethingSelected() || cm.getOption("disableInput")) return CodeMirror.Pass;
32
- var cur = cm.getCursor(), around = charsAround(cm, cur);
33
- if (around && pairs.indexOf(around) % 2 == 0)
38
+ if (cm.getOption("disableInput")) return CodeMirror.Pass;
39
+ var ranges = cm.listSelections();
40
+ for (var i = 0; i < ranges.length; i++) {
41
+ if (!ranges[i].empty()) return CodeMirror.Pass;
42
+ var around = charsAround(cm, ranges[i].head);
43
+ if (!around || pairs.indexOf(around) % 2 != 0) return CodeMirror.Pass;
44
+ }
45
+ for (var i = ranges.length - 1; i >= 0; i--) {
46
+ var cur = ranges[i].head;
34
47
  cm.replaceRange("", CodeMirror.Pos(cur.line, cur.ch - 1), CodeMirror.Pos(cur.line, cur.ch + 1));
35
- else
36
- return CodeMirror.Pass;
48
+ }
37
49
  }
38
50
  };
39
51
  var closingBrackets = "";
40
52
  for (var i = 0; i < pairs.length; i += 2) (function(left, right) {
41
53
  if (left != right) closingBrackets += right;
42
- function surround(cm) {
43
- var selection = cm.getSelection();
44
- cm.replaceSelection(left + selection + right);
45
- }
46
- function maybeOverwrite(cm) {
47
- var cur = cm.getCursor(), ahead = cm.getRange(cur, CodeMirror.Pos(cur.line, cur.ch + 1));
48
- if (ahead != right || cm.somethingSelected()) return CodeMirror.Pass;
49
- else cm.execCommand("goCharRight");
50
- }
51
54
  map["'" + left + "'"] = function(cm) {
52
- if (left == "'" && cm.getTokenAt(cm.getCursor()).type == "comment" ||
53
- cm.getOption("disableInput"))
54
- return CodeMirror.Pass;
55
- if (cm.somethingSelected()) return surround(cm);
56
- if (left == right && maybeOverwrite(cm) != CodeMirror.Pass) return;
57
- var cur = cm.getCursor(), ahead = CodeMirror.Pos(cur.line, cur.ch + 1);
58
- var line = cm.getLine(cur.line), nextChar = line.charAt(cur.ch), curChar = cur.ch > 0 ? line.charAt(cur.ch - 1) : "";
59
- if (left == right && CodeMirror.isWordChar(curChar))
60
- return CodeMirror.Pass;
61
- if (line.length == cur.ch || closingBrackets.indexOf(nextChar) >= 0 || SPACE_CHAR_REGEX.test(nextChar))
62
- cm.replaceSelection(left + right, {head: ahead, anchor: ahead});
63
- else
64
- return CodeMirror.Pass;
55
+ if (cm.getOption("disableInput")) return CodeMirror.Pass;
56
+ var ranges = cm.listSelections(), type, next;
57
+ for (var i = 0; i < ranges.length; i++) {
58
+ var range = ranges[i], cur = range.head, curType;
59
+ if (left == "'" && cm.getTokenTypeAt(cur) == "comment")
60
+ return CodeMirror.Pass;
61
+ var next = cm.getRange(cur, CodeMirror.Pos(cur.line, cur.ch + 1));
62
+ if (!range.empty())
63
+ curType = "surround";
64
+ else if (left == right && next == right)
65
+ curType = "skip";
66
+ else if (left == right && CodeMirror.isWordChar(next))
67
+ return CodeMirror.Pass;
68
+ else if (cm.getLine(cur.line).length == cur.ch || closingBrackets.indexOf(next) >= 0 || SPACE_CHAR_REGEX.test(next))
69
+ curType = "both";
70
+ else
71
+ return CodeMirror.Pass;
72
+ if (!type) type = curType;
73
+ else if (type != curType) return CodeMirror.Pass;
74
+ }
75
+
76
+ if (type == "skip") {
77
+ cm.execCommand("goCharRight");
78
+ } else if (type == "surround") {
79
+ var sels = cm.getSelections();
80
+ for (var i = 0; i < sels.length; i++)
81
+ sels[i] = left + sels[i] + right;
82
+ cm.replaceSelections(sels, "around");
83
+ } else if (type == "both") {
84
+ cm.replaceSelection(left + right, null);
85
+ cm.execCommand("goCharLeft");
86
+ }
87
+ };
88
+ if (left != right) map["'" + right + "'"] = function(cm) {
89
+ var ranges = cm.listSelections();
90
+ for (var i = 0; i < ranges.length; i++) {
91
+ var range = ranges[i];
92
+ if (!range.empty() ||
93
+ cm.getRange(range.head, CodeMirror.Pos(range.head.line, range.head.ch + 1)) != right)
94
+ return CodeMirror.Pass;
95
+ }
96
+ cm.execCommand("goCharRight");
65
97
  };
66
- if (left != right) map["'" + right + "'"] = maybeOverwrite;
67
98
  })(pairs.charAt(i), pairs.charAt(i + 1));
68
99
  return map;
69
100
  }
70
101
 
71
102
  function buildExplodeHandler(pairs) {
72
103
  return function(cm) {
73
- var cur = cm.getCursor(), around = charsAround(cm, cur);
74
- if (!around || pairs.indexOf(around) % 2 != 0 || cm.getOption("disableInput"))
75
- return CodeMirror.Pass;
104
+ if (cm.getOption("disableInput")) return CodeMirror.Pass;
105
+ var ranges = cm.listSelections();
106
+ for (var i = 0; i < ranges.length; i++) {
107
+ if (!ranges[i].empty()) return CodeMirror.Pass;
108
+ var around = charsAround(cm, ranges[i].head);
109
+ if (!around || pairs.indexOf(around) % 2 != 0) return CodeMirror.Pass;
110
+ }
76
111
  cm.operation(function() {
77
- var newPos = CodeMirror.Pos(cur.line + 1, 0);
78
- cm.replaceSelection("\n\n", {anchor: newPos, head: newPos}, "+input");
79
- cm.indentLine(cur.line + 1, null, true);
80
- cm.indentLine(cur.line + 2, null, true);
112
+ cm.replaceSelection("\n\n", null);
113
+ cm.execCommand("goCharLeft");
114
+ ranges = cm.listSelections();
115
+ for (var i = 0; i < ranges.length; i++) {
116
+ var line = ranges[i].head.line;
117
+ cm.indentLine(line, null, true);
118
+ cm.indentLine(line + 1, null, true);
119
+ }
81
120
  });
82
121
  };
83
122
  }
84
- })();
123
+ });
@@ -22,7 +22,14 @@
22
22
  * See demos/closetag.html for a usage example.
23
23
  */
24
24
 
25
- (function() {
25
+ (function(mod) {
26
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
27
+ mod(require("../../lib/codemirror"), require("../fold/xml-fold"));
28
+ else if (typeof define == "function" && define.amd) // AMD
29
+ define(["../../lib/codemirror", "../fold/xml-fold"], mod);
30
+ else // Plain browser env
31
+ mod(CodeMirror);
32
+ })(function(CodeMirror) {
26
33
  CodeMirror.defineOption("autoCloseTags", false, function(cm, val, old) {
27
34
  if (old != CodeMirror.Init && old)
28
35
  cm.removeKeyMap("autoCloseTags");
@@ -41,48 +48,63 @@
41
48
  "h5", "h6", "head", "html", "iframe", "layer", "legend", "object", "ol", "p", "select", "table", "ul"];
42
49
 
43
50
  function autoCloseGT(cm) {
44
- var pos = cm.getCursor(), tok = cm.getTokenAt(pos);
45
- var inner = CodeMirror.innerMode(cm.getMode(), tok.state), state = inner.state;
46
- if (inner.mode.name != "xml" || !state.tagName || cm.getOption("disableInput")) return CodeMirror.Pass;
51
+ if (cm.getOption("disableInput")) return CodeMirror.Pass;
52
+ var ranges = cm.listSelections(), replacements = [];
53
+ for (var i = 0; i < ranges.length; i++) {
54
+ if (!ranges[i].empty()) return CodeMirror.Pass;
55
+ var pos = ranges[i].head, tok = cm.getTokenAt(pos);
56
+ var inner = CodeMirror.innerMode(cm.getMode(), tok.state), state = inner.state;
57
+ if (inner.mode.name != "xml" || !state.tagName) return CodeMirror.Pass;
58
+ var opt = cm.getOption("autoCloseTags"), html = inner.mode.configuration == "html";
59
+ var dontCloseTags = (typeof opt == "object" && opt.dontCloseTags) || (html && htmlDontClose);
60
+ var indentTags = (typeof opt == "object" && opt.indentTags) || (html && htmlIndent);
47
61
 
48
- var opt = cm.getOption("autoCloseTags"), html = inner.mode.configuration == "html";
49
- var dontCloseTags = (typeof opt == "object" && opt.dontCloseTags) || (html && htmlDontClose);
50
- var indentTags = (typeof opt == "object" && opt.indentTags) || (html && htmlIndent);
62
+ var tagName = state.tagName;
63
+ if (tok.end > pos.ch) tagName = tagName.slice(0, tagName.length - tok.end + pos.ch);
64
+ var lowerTagName = tagName.toLowerCase();
65
+ // Don't process the '>' at the end of an end-tag or self-closing tag
66
+ if (!tagName ||
67
+ tok.type == "string" && (tok.end != pos.ch || !/[\"\']/.test(tok.string.charAt(tok.string.length - 1)) || tok.string.length == 1) ||
68
+ tok.type == "tag" && state.type == "closeTag" ||
69
+ tok.string.indexOf("/") == (tok.string.length - 1) || // match something like <someTagName />
70
+ dontCloseTags && indexOf(dontCloseTags, lowerTagName) > -1 ||
71
+ CodeMirror.scanForClosingTag && CodeMirror.scanForClosingTag(cm, pos, tagName,
72
+ Math.min(cm.lastLine() + 1, pos.line + 50)))
73
+ return CodeMirror.Pass;
51
74
 
52
- var tagName = state.tagName;
53
- if (tok.end > pos.ch) tagName = tagName.slice(0, tagName.length - tok.end + pos.ch);
54
- var lowerTagName = tagName.toLowerCase();
55
- // Don't process the '>' at the end of an end-tag or self-closing tag
56
- if (!tagName ||
57
- tok.type == "string" && (tok.end != pos.ch || !/[\"\']/.test(tok.string.charAt(tok.string.length - 1)) || tok.string.length == 1) ||
58
- tok.type == "tag" && state.type == "closeTag" ||
59
- tok.string.indexOf("/") == (tok.string.length - 1) || // match something like <someTagName />
60
- dontCloseTags && indexOf(dontCloseTags, lowerTagName) > -1 ||
61
- CodeMirror.scanForClosingTag && CodeMirror.scanForClosingTag(cm, pos, tagName,
62
- Math.min(cm.lastLine() + 1, pos.line + 50)))
63
- return CodeMirror.Pass;
75
+ var indent = indentTags && indexOf(indentTags, lowerTagName) > -1;
76
+ replacements[i] = {indent: indent,
77
+ text: ">" + (indent ? "\n\n" : "") + "</" + tagName + ">",
78
+ newPos: indent ? CodeMirror.Pos(pos.line + 1, 0) : CodeMirror.Pos(pos.line, pos.ch + 1)};
79
+ }
64
80
 
65
- var doIndent = indentTags && indexOf(indentTags, lowerTagName) > -1;
66
- var curPos = doIndent ? CodeMirror.Pos(pos.line + 1, 0) : CodeMirror.Pos(pos.line, pos.ch + 1);
67
- cm.replaceSelection(">" + (doIndent ? "\n\n" : "") + "</" + tagName + ">",
68
- {head: curPos, anchor: curPos});
69
- if (doIndent) {
70
- cm.indentLine(pos.line + 1, null, true);
71
- cm.indentLine(pos.line + 2, null);
81
+ for (var i = ranges.length - 1; i >= 0; i--) {
82
+ var info = replacements[i];
83
+ cm.replaceRange(info.text, ranges[i].head, ranges[i].anchor, "+insert");
84
+ var sel = cm.listSelections().slice(0);
85
+ sel[i] = {head: info.newPos, anchor: info.newPos};
86
+ cm.setSelections(sel);
87
+ if (info.indent) {
88
+ cm.indentLine(info.newPos.line, null, true);
89
+ cm.indentLine(info.newPos.line + 1, null, true);
90
+ }
72
91
  }
73
92
  }
74
93
 
75
94
  function autoCloseSlash(cm) {
76
- var pos = cm.getCursor(), tok = cm.getTokenAt(pos);
77
- var inner = CodeMirror.innerMode(cm.getMode(), tok.state), state = inner.state;
78
- if (tok.type == "string" || tok.string.charAt(0) != "<" ||
79
- tok.start != pos.ch - 1 || inner.mode.name != "xml" ||
80
- cm.getOption("disableInput"))
81
- return CodeMirror.Pass;
82
-
83
- var tagName = state.context && state.context.tagName;
84
- if (tagName) cm.replaceSelection("/" + tagName + ">", "end");
85
- else return CodeMirror.Pass;
95
+ if (cm.getOption("disableInput")) return CodeMirror.Pass;
96
+ var ranges = cm.listSelections(), replacements = [];
97
+ for (var i = 0; i < ranges.length; i++) {
98
+ if (!ranges[i].empty()) return CodeMirror.Pass;
99
+ var pos = ranges[i].head, tok = cm.getTokenAt(pos);
100
+ var inner = CodeMirror.innerMode(cm.getMode(), tok.state), state = inner.state;
101
+ if (tok.type == "string" || tok.string.charAt(0) != "<" ||
102
+ tok.start != pos.ch - 1 || inner.mode.name != "xml" ||
103
+ !state.context || !state.context.tagName)
104
+ return CodeMirror.Pass;
105
+ replacements[i] = "/" + state.context.tagName + ">";
106
+ }
107
+ cm.replaceSelections(replacements);
86
108
  }
87
109
 
88
110
  function indexOf(collection, elt) {
@@ -91,4 +113,4 @@
91
113
  if (collection[i] == elt) return i;
92
114
  return -1;
93
115
  }
94
- })();
116
+ });