codemirror-rails 3.24 → 4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/codemirror/rails/version.rb +2 -2
- data/vendor/assets/javascripts/codemirror.js +3001 -1798
- data/vendor/assets/javascripts/codemirror/addons/comment/comment.js +24 -4
- data/vendor/assets/javascripts/codemirror/addons/comment/continuecomment.js +47 -32
- data/vendor/assets/javascripts/codemirror/addons/dialog/dialog.js +9 -2
- data/vendor/assets/javascripts/codemirror/addons/display/fullscreen.js +9 -2
- data/vendor/assets/javascripts/codemirror/addons/display/placeholder.js +9 -2
- data/vendor/assets/javascripts/codemirror/addons/display/rulers.js +9 -2
- data/vendor/assets/javascripts/codemirror/addons/edit/closebrackets.js +76 -37
- data/vendor/assets/javascripts/codemirror/addons/edit/closetag.js +59 -37
- data/vendor/assets/javascripts/codemirror/addons/edit/continuelist.js +25 -17
- data/vendor/assets/javascripts/codemirror/addons/edit/matchbrackets.js +67 -46
- data/vendor/assets/javascripts/codemirror/addons/edit/matchtags.js +10 -3
- data/vendor/assets/javascripts/codemirror/addons/edit/trailingspace.js +23 -14
- data/vendor/assets/javascripts/codemirror/addons/fold/brace-fold.js +12 -3
- data/vendor/assets/javascripts/codemirror/addons/fold/comment-fold.js +12 -0
- data/vendor/assets/javascripts/codemirror/addons/fold/foldcode.js +28 -3
- data/vendor/assets/javascripts/codemirror/addons/fold/foldgutter.js +9 -2
- data/vendor/assets/javascripts/codemirror/addons/fold/indent-fold.js +12 -1
- data/vendor/assets/javascripts/codemirror/addons/fold/markdown-fold.js +12 -0
- data/vendor/assets/javascripts/codemirror/addons/fold/xml-fold.js +9 -4
- data/vendor/assets/javascripts/codemirror/addons/hint/anyword-hint.js +9 -2
- data/vendor/assets/javascripts/codemirror/addons/hint/css-hint.js +10 -3
- data/vendor/assets/javascripts/codemirror/addons/hint/html-hint.js +11 -3
- data/vendor/assets/javascripts/codemirror/addons/hint/javascript-hint.js +9 -4
- data/vendor/assets/javascripts/codemirror/addons/hint/python-hint.js +11 -3
- data/vendor/assets/javascripts/codemirror/addons/hint/show-hint.js +10 -4
- data/vendor/assets/javascripts/codemirror/addons/hint/sql-hint.js +9 -2
- data/vendor/assets/javascripts/codemirror/addons/hint/xml-hint.js +22 -34
- data/vendor/assets/javascripts/codemirror/addons/lint/coffeescript-lint.js +12 -1
- data/vendor/assets/javascripts/codemirror/addons/lint/css-lint.js +12 -1
- data/vendor/assets/javascripts/codemirror/addons/lint/javascript-lint.js +9 -4
- data/vendor/assets/javascripts/codemirror/addons/lint/json-lint.js +12 -1
- data/vendor/assets/javascripts/codemirror/addons/lint/lint.js +12 -8
- data/vendor/assets/javascripts/codemirror/addons/lint/yaml-lint.js +12 -1
- data/vendor/assets/javascripts/codemirror/addons/merge/merge.js +18 -16
- data/vendor/assets/javascripts/codemirror/addons/mode/loadmode.js +9 -2
- data/vendor/assets/javascripts/codemirror/addons/mode/multiplex.js +12 -0
- data/vendor/assets/javascripts/codemirror/addons/mode/overlay.js +15 -10
- data/vendor/assets/javascripts/codemirror/addons/runmode/colorize.js +11 -3
- data/vendor/assets/javascripts/codemirror/addons/runmode/runmode-standalone.js +0 -2
- data/vendor/assets/javascripts/codemirror/addons/runmode/runmode.js +12 -0
- data/vendor/assets/javascripts/codemirror/addons/runmode/runmode.node.js +4 -0
- data/vendor/assets/javascripts/codemirror/addons/scroll/scrollpastend.js +9 -2
- data/vendor/assets/javascripts/codemirror/addons/search/match-highlighter.js +12 -3
- data/vendor/assets/javascripts/codemirror/addons/search/search.js +24 -16
- data/vendor/assets/javascripts/codemirror/addons/search/searchcursor.js +21 -2
- data/vendor/assets/javascripts/codemirror/addons/selection/active-line.js +38 -17
- data/vendor/assets/javascripts/codemirror/addons/selection/mark-selection.js +16 -9
- data/vendor/assets/javascripts/codemirror/addons/tern/tern.js +33 -5
- data/vendor/assets/javascripts/codemirror/addons/wrap/hardwrap.js +27 -2
- data/vendor/assets/javascripts/codemirror/keymaps/emacs.js +12 -5
- data/vendor/assets/javascripts/codemirror/keymaps/sublime.js +505 -0
- data/vendor/assets/javascripts/codemirror/keymaps/vim.js +138 -179
- data/vendor/assets/javascripts/codemirror/modes/apl.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/asterisk.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/clike.js +15 -4
- data/vendor/assets/javascripts/codemirror/modes/clojure.js +13 -0
- data/vendor/assets/javascripts/codemirror/modes/cobol.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/coffeescript.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/commonlisp.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/css.js +18 -27
- data/vendor/assets/javascripts/codemirror/modes/d.js +12 -2
- data/vendor/assets/javascripts/codemirror/modes/diff.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/dtd.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/ecl.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/eiffel.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/erlang.js +13 -1
- data/vendor/assets/javascripts/codemirror/modes/fortran.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/gas.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/gfm.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/gherkin.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/go.js +12 -1
- data/vendor/assets/javascripts/codemirror/modes/groovy.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/haml.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/haskell.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/haxe.js +18 -9
- data/vendor/assets/javascripts/codemirror/modes/htmlembedded.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/htmlmixed.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/http.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/jade.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/javascript.js +23 -16
- data/vendor/assets/javascripts/codemirror/modes/jinja2.js +53 -118
- data/vendor/assets/javascripts/codemirror/modes/julia.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/livescript.js +17 -4
- data/vendor/assets/javascripts/codemirror/modes/lua.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/markdown.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/mirc.js +13 -0
- data/vendor/assets/javascripts/codemirror/modes/mllike.js +12 -1
- data/vendor/assets/javascripts/codemirror/modes/nginx.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/ntriples.js +13 -0
- data/vendor/assets/javascripts/codemirror/modes/octave.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/pascal.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/pegjs.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/perl.js +84 -73
- data/vendor/assets/javascripts/codemirror/modes/php.js +20 -101
- data/vendor/assets/javascripts/codemirror/modes/pig.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/properties.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/puppet.js +13 -0
- data/vendor/assets/javascripts/codemirror/modes/python.js +21 -11
- data/vendor/assets/javascripts/codemirror/modes/q.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/r.js +13 -3
- data/vendor/assets/javascripts/codemirror/modes/{rpm-spec.js → rpm.js} +34 -2
- data/vendor/assets/javascripts/codemirror/modes/rst.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/ruby.js +11 -0
- data/vendor/assets/javascripts/codemirror/modes/rust.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/sass.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/scheme.js +13 -0
- data/vendor/assets/javascripts/codemirror/modes/shell.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/sieve.js +11 -4
- data/vendor/assets/javascripts/codemirror/modes/smalltalk.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/smarty.js +13 -0
- data/vendor/assets/javascripts/codemirror/modes/smartymixed.js +14 -2
- data/vendor/assets/javascripts/codemirror/modes/solr.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/sparql.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/sql.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/stex.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/tcl.js +13 -0
- data/vendor/assets/javascripts/codemirror/modes/tiddlywiki.js +13 -0
- data/vendor/assets/javascripts/codemirror/modes/tiki.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/toml.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/turtle.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/vb.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/vbscript.js +13 -0
- data/vendor/assets/javascripts/codemirror/modes/velocity.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/verilog.js +89 -236
- data/vendor/assets/javascripts/codemirror/modes/xml.js +41 -60
- data/vendor/assets/javascripts/codemirror/modes/xquery.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/yaml.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/z80.js +12 -0
- data/vendor/assets/stylesheets/codemirror.css +15 -10
- data/vendor/assets/stylesheets/codemirror/themes/ambiance.css +1 -0
- data/vendor/assets/stylesheets/codemirror/themes/lesser-dark.css +4 -0
- data/vendor/assets/stylesheets/codemirror/themes/mdn-like.css +1 -1
- data/vendor/assets/stylesheets/codemirror/themes/pastel-on-dark.css +1 -0
- data/vendor/assets/stylesheets/codemirror/themes/rubyblue.css +2 -0
- data/vendor/assets/stylesheets/codemirror/themes/solarized.css +17 -3
- metadata +20 -25
- data/vendor/assets/javascripts/codemirror/keymaps/extra.js +0 -43
- data/vendor/assets/javascripts/codemirror/modes/django.js +0 -55
- data/vendor/assets/javascripts/codemirror/modes/dylan.js +0 -284
- data/vendor/assets/javascripts/codemirror/modes/less.js +0 -347
- data/vendor/assets/javascripts/codemirror/modes/rpm-changes.js +0 -19
- 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
|
15
|
-
|
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
|
-
|
9
|
-
|
10
|
-
var
|
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
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
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
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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.
|
32
|
-
var
|
33
|
-
|
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
|
-
|
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 (
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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
|
-
|
74
|
-
|
75
|
-
|
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
|
-
|
78
|
-
cm.
|
79
|
-
cm.
|
80
|
-
|
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
|
-
|
45
|
-
var
|
46
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
cm.
|
71
|
-
|
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
|
-
|
77
|
-
var
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
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
|
+
});
|