codemirror-rails 3.02 → 3.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +1 -1
- data/LICENSE +1 -1
- data/codemirror-rails.gemspec +1 -0
- data/doc/CodeMirror-LICENSE +5 -1
- data/lib/codemirror/rails/version.rb +2 -2
- data/vendor/assets/javascripts/codemirror/{utils → addons/dialog}/dialog.js +4 -0
- data/vendor/assets/javascripts/codemirror/addons/display/placeholder.js +54 -0
- data/vendor/assets/javascripts/codemirror/addons/edit/closebrackets.js +54 -0
- data/vendor/assets/javascripts/codemirror/{utils → addons/edit}/closetag.js +9 -8
- data/vendor/assets/javascripts/codemirror/{utils → addons/edit}/continuecomment.js +12 -4
- data/vendor/assets/javascripts/codemirror/addons/edit/continuelist.js +25 -0
- data/vendor/assets/javascripts/codemirror/{utils → addons/edit}/matchbrackets.js +30 -11
- data/vendor/assets/javascripts/codemirror/addons/fold/brace-fold.js +31 -0
- data/vendor/assets/javascripts/codemirror/addons/fold/foldcode.js +32 -0
- data/vendor/assets/javascripts/codemirror/addons/fold/indent-fold.js +11 -0
- data/vendor/assets/javascripts/codemirror/addons/fold/xml-fold.js +64 -0
- data/vendor/assets/javascripts/codemirror/addons/hint/html-hint.js +582 -0
- data/vendor/assets/javascripts/codemirror/{utils → addons/hint}/javascript-hint.js +15 -11
- data/vendor/assets/javascripts/codemirror/{utils → addons/hint}/pig-hint.js +19 -19
- data/vendor/assets/javascripts/codemirror/{utils → addons/hint}/python-hint.js +2 -2
- data/vendor/assets/javascripts/codemirror/addons/hint/show-hint.js +180 -0
- data/vendor/assets/javascripts/codemirror/{utils → addons/hint}/xml-hint.js +5 -18
- data/vendor/assets/javascripts/codemirror/addons/lint/javascript-lint.js +127 -0
- data/vendor/assets/javascripts/codemirror/addons/lint/json-lint.js +14 -0
- data/vendor/assets/javascripts/codemirror/addons/lint/lint.js +197 -0
- data/vendor/assets/javascripts/codemirror/{utils → addons/mode}/loadmode.js +0 -0
- data/vendor/assets/javascripts/codemirror/{utils → addons/mode}/multiplex.js +2 -2
- data/vendor/assets/javascripts/codemirror/{utils → addons/mode}/overlay.js +2 -2
- data/vendor/assets/javascripts/codemirror/{utils → addons/runmode}/colorize.js +0 -0
- data/vendor/assets/javascripts/codemirror/{utils → addons/runmode}/runmode-standalone.js +2 -3
- data/vendor/assets/javascripts/codemirror/{utils → addons/runmode}/runmode.js +0 -0
- data/vendor/assets/javascripts/codemirror/addons/runmode/runmode.node.js +89 -0
- data/vendor/assets/javascripts/codemirror/addons/search/match-highlighter.js +60 -0
- data/vendor/assets/javascripts/codemirror/{utils → addons/search}/search.js +5 -5
- data/vendor/assets/javascripts/codemirror/{utils → addons/search}/searchcursor.js +37 -30
- data/vendor/assets/javascripts/codemirror/addons/selection/active-line.js +39 -0
- data/vendor/assets/javascripts/codemirror/addons/selection/mark-selection.js +34 -0
- data/vendor/assets/javascripts/codemirror/keymaps/vim.js +721 -188
- data/vendor/assets/javascripts/codemirror/modes/asterisk.js +6 -6
- data/vendor/assets/javascripts/codemirror/modes/clike.js +14 -14
- data/vendor/assets/javascripts/codemirror/modes/clojure.js +23 -7
- data/vendor/assets/javascripts/codemirror/modes/coffeescript.js +2 -2
- data/vendor/assets/javascripts/codemirror/modes/css.js +337 -235
- data/vendor/assets/javascripts/codemirror/modes/ecl.js +12 -12
- data/vendor/assets/javascripts/codemirror/modes/erlang.js +1 -1
- data/vendor/assets/javascripts/codemirror/modes/gas.js +326 -0
- data/vendor/assets/javascripts/codemirror/modes/gfm.js +1 -0
- data/vendor/assets/javascripts/codemirror/modes/haskell.js +26 -26
- data/vendor/assets/javascripts/codemirror/modes/haxe.js +17 -17
- data/vendor/assets/javascripts/codemirror/modes/htmlembedded.js +6 -6
- data/vendor/assets/javascripts/codemirror/modes/htmlmixed.js +43 -23
- data/vendor/assets/javascripts/codemirror/modes/javascript.js +78 -33
- data/vendor/assets/javascripts/codemirror/modes/jinja2.js +2 -2
- data/vendor/assets/javascripts/codemirror/modes/less.js +38 -38
- data/vendor/assets/javascripts/codemirror/modes/livescript.js +267 -0
- data/vendor/assets/javascripts/codemirror/modes/lua.js +7 -7
- data/vendor/assets/javascripts/codemirror/modes/markdown.js +108 -57
- data/vendor/assets/javascripts/codemirror/modes/mirc.js +177 -0
- data/vendor/assets/javascripts/codemirror/modes/ntriples.js +22 -22
- data/vendor/assets/javascripts/codemirror/modes/ocaml.js +1 -1
- data/vendor/assets/javascripts/codemirror/modes/perl.js +791 -791
- data/vendor/assets/javascripts/codemirror/modes/php.js +1 -1
- data/vendor/assets/javascripts/codemirror/modes/pig.js +163 -163
- data/vendor/assets/javascripts/codemirror/modes/python.js +31 -31
- data/vendor/assets/javascripts/codemirror/modes/q.js +124 -0
- data/vendor/assets/javascripts/codemirror/modes/rst.js +486 -250
- data/vendor/assets/javascripts/codemirror/modes/sass.js +3 -3
- data/vendor/assets/javascripts/codemirror/modes/scss_test.js +80 -0
- data/vendor/assets/javascripts/codemirror/modes/shell.js +2 -2
- data/vendor/assets/javascripts/codemirror/modes/sieve.js +10 -10
- data/vendor/assets/javascripts/codemirror/modes/smalltalk.js +129 -129
- data/vendor/assets/javascripts/codemirror/modes/smarty.js +3 -3
- data/vendor/assets/javascripts/codemirror/modes/sparql.js +1 -1
- data/vendor/assets/javascripts/codemirror/modes/sql.js +23 -23
- data/vendor/assets/javascripts/codemirror/modes/stex.js +192 -121
- data/vendor/assets/javascripts/codemirror/modes/tcl.js +131 -0
- data/vendor/assets/javascripts/codemirror/modes/test.js +64 -0
- data/vendor/assets/javascripts/codemirror/modes/tiddlywiki.js +345 -345
- data/vendor/assets/javascripts/codemirror/modes/tiki.js +297 -298
- data/vendor/assets/javascripts/codemirror/modes/turtle.js +145 -0
- data/vendor/assets/javascripts/codemirror/modes/vb.js +31 -32
- data/vendor/assets/javascripts/codemirror/modes/vbscript.js +4 -4
- data/vendor/assets/javascripts/codemirror/modes/xml.js +10 -6
- data/vendor/assets/javascripts/codemirror/modes/xquery.js +55 -55
- data/vendor/assets/javascripts/codemirror/modes/yaml.js +90 -90
- data/vendor/assets/javascripts/codemirror/modes/z80.js +82 -110
- data/vendor/assets/javascripts/codemirror.js +1914 -1115
- data/vendor/assets/stylesheets/codemirror/{utils → addons/dialog}/dialog.css +0 -0
- data/vendor/assets/stylesheets/codemirror/addons/hint/show-hint.css +38 -0
- data/vendor/assets/stylesheets/codemirror/addons/lint/lint.css +96 -0
- data/vendor/assets/stylesheets/codemirror/modes/tiki.css +2 -2
- data/vendor/assets/stylesheets/codemirror/themes/ambiance-mobile.css +0 -1
- data/vendor/assets/stylesheets/codemirror/themes/ambiance.css +0 -1
- data/vendor/assets/stylesheets/codemirror/themes/eclipse.css +2 -2
- data/vendor/assets/stylesheets/codemirror/themes/erlang-dark.css +5 -5
- data/vendor/assets/stylesheets/codemirror/themes/midnight.css +52 -0
- data/vendor/assets/stylesheets/codemirror/themes/xq-light.css +43 -0
- data/vendor/assets/stylesheets/codemirror.css +16 -10
- metadata +60 -52
- data/vendor/assets/javascripts/codemirror/modes/mysql.js +0 -203
- data/vendor/assets/javascripts/codemirror/modes/plsql.js +0 -216
- data/vendor/assets/javascripts/codemirror/utils/collapserange.js +0 -68
- data/vendor/assets/javascripts/codemirror/utils/continuelist.js +0 -28
- data/vendor/assets/javascripts/codemirror/utils/foldcode.js +0 -183
- data/vendor/assets/javascripts/codemirror/utils/formatting.js +0 -114
- data/vendor/assets/javascripts/codemirror/utils/match-highlighter.js +0 -46
- data/vendor/assets/javascripts/codemirror/utils/simple-hint.js +0 -102
- data/vendor/assets/stylesheets/codemirror/utils/simple-hint.css +0 -16
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2427ad0abadb3c23235f0807a459c7f5d8aad5b6
|
4
|
+
data.tar.gz: 3feb14d065dfe7f9cd5633dd11a19879c6790345
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9ed90ea774b637f9c6565bb836db4fe6aef30cc9a2317af6865056141b65b1d1dbecfa4853df73bdee3356f5233a0504dae79a93c845941be3f09f6cbfdc92ad
|
7
|
+
data.tar.gz: 8eecc04dce862ef3803ce8ce35f6c15979d575c45121a4c95c660afbdb008a54e6fa112c209a828225bc73447ff3d8a83fd3d80de1cf79ff2470946e54403eb9
|
data/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
gemspec
|
data/LICENSE
CHANGED
data/codemirror-rails.gemspec
CHANGED
@@ -5,6 +5,7 @@ Gem::Specification.new do |s|
|
|
5
5
|
s.version = Codemirror::Rails::VERSION
|
6
6
|
s.authors = ['Nathan Fixler']
|
7
7
|
s.email = 'nathan@fixler.org'
|
8
|
+
s.license = 'MIT'
|
8
9
|
s.summary = 'Use CodeMirror with Rails 3'
|
9
10
|
s.description = 'This gem provides CodeMirror assets for your Rails 3 application.'
|
10
11
|
s.homepage = 'https://rubygems.org/gems/codemirror-rails'
|
data/doc/CodeMirror-LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (C)
|
1
|
+
Copyright (C) 2013 by Marijn Haverbeke <marijnh@gmail.com>
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
of this software and associated documentation files (the "Software"), to deal
|
@@ -17,3 +17,7 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
17
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
18
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
19
|
THE SOFTWARE.
|
20
|
+
|
21
|
+
Please note that some subdirectories of the CodeMirror distribution
|
22
|
+
include their own LICENSE files, and are released under different
|
23
|
+
licences.
|
@@ -25,6 +25,7 @@
|
|
25
25
|
var inp = dialog.getElementsByTagName("input")[0], button;
|
26
26
|
if (inp) {
|
27
27
|
CodeMirror.on(inp, "keydown", function(e) {
|
28
|
+
if (options && options.onKeyDown && options.onKeyDown(e, inp.value, close)) { return; }
|
28
29
|
if (e.keyCode == 13 || e.keyCode == 27) {
|
29
30
|
CodeMirror.e_stop(e);
|
30
31
|
close();
|
@@ -32,6 +33,9 @@
|
|
32
33
|
if (e.keyCode == 13) callback(inp.value);
|
33
34
|
}
|
34
35
|
});
|
36
|
+
if (options && options.onKeyUp) {
|
37
|
+
CodeMirror.on(inp, "keyup", function(e) {options.onKeyUp(e, inp.value, close);});
|
38
|
+
}
|
35
39
|
if (options && options.value) inp.value = options.value;
|
36
40
|
inp.focus();
|
37
41
|
CodeMirror.on(inp, "blur", close);
|
@@ -0,0 +1,54 @@
|
|
1
|
+
(function() {
|
2
|
+
CodeMirror.defineOption("placeholder", "", function(cm, val, old) {
|
3
|
+
var prev = old && old != CodeMirror.Init;
|
4
|
+
if (val && !prev) {
|
5
|
+
cm.on("focus", onFocus);
|
6
|
+
cm.on("blur", onBlur);
|
7
|
+
cm.on("change", onChange);
|
8
|
+
onChange(cm);
|
9
|
+
} else if (!val && prev) {
|
10
|
+
cm.off("focus", onFocus);
|
11
|
+
cm.off("blur", onBlur);
|
12
|
+
cm.off("change", onChange);
|
13
|
+
clearPlaceholder(cm);
|
14
|
+
var wrapper = cm.getWrapperElement();
|
15
|
+
wrapper.className = wrapper.className.replace(" CodeMirror-empty", "");
|
16
|
+
}
|
17
|
+
|
18
|
+
if (val && !cm.hasFocus()) onBlur(cm);
|
19
|
+
});
|
20
|
+
|
21
|
+
function clearPlaceholder(cm) {
|
22
|
+
if (cm._placeholder) {
|
23
|
+
cm._placeholder.parentNode.removeChild(cm._placeholder);
|
24
|
+
cm._placeholder = null;
|
25
|
+
}
|
26
|
+
}
|
27
|
+
function setPlaceholder(cm) {
|
28
|
+
clearPlaceholder(cm);
|
29
|
+
var elt = cm._placeholder = document.createElement("pre");
|
30
|
+
elt.style.cssText = "height: 0; overflow: visible";
|
31
|
+
elt.className = "CodeMirror-placeholder";
|
32
|
+
elt.appendChild(document.createTextNode(cm.getOption("placeholder")));
|
33
|
+
cm.display.lineSpace.insertBefore(elt, cm.display.lineSpace.firstChild);
|
34
|
+
}
|
35
|
+
|
36
|
+
function onFocus(cm) {
|
37
|
+
clearPlaceholder(cm);
|
38
|
+
}
|
39
|
+
function onBlur(cm) {
|
40
|
+
if (isEmpty(cm)) setPlaceholder(cm);
|
41
|
+
}
|
42
|
+
function onChange(cm) {
|
43
|
+
var wrapper = cm.getWrapperElement(), empty = isEmpty(cm);
|
44
|
+
wrapper.className = wrapper.className.replace(" CodeMirror-empty", "") + (empty ? " CodeMirror-empty" : "");
|
45
|
+
|
46
|
+
if (cm.hasFocus()) return;
|
47
|
+
if (empty) setPlaceholder(cm);
|
48
|
+
else clearPlaceholder(cm);
|
49
|
+
}
|
50
|
+
|
51
|
+
function isEmpty(cm) {
|
52
|
+
return (cm.lineCount() === 1) && (cm.getLine(0) === "");
|
53
|
+
}
|
54
|
+
})();
|
@@ -0,0 +1,54 @@
|
|
1
|
+
(function() {
|
2
|
+
var DEFAULT_BRACKETS = "()[]{}''\"\"";
|
3
|
+
var SPACE_CHAR_REGEX = /\s/;
|
4
|
+
|
5
|
+
CodeMirror.defineOption("autoCloseBrackets", false, function(cm, val, old) {
|
6
|
+
var wasOn = old && old != CodeMirror.Init;
|
7
|
+
if (val && !wasOn)
|
8
|
+
cm.addKeyMap(buildKeymap(typeof val == "string" ? val : DEFAULT_BRACKETS));
|
9
|
+
else if (!val && wasOn)
|
10
|
+
cm.removeKeyMap("autoCloseBrackets");
|
11
|
+
});
|
12
|
+
|
13
|
+
function buildKeymap(pairs) {
|
14
|
+
var map = {
|
15
|
+
name : "autoCloseBrackets",
|
16
|
+
Backspace: function(cm) {
|
17
|
+
if (cm.somethingSelected()) return CodeMirror.Pass;
|
18
|
+
var cur = cm.getCursor(), line = cm.getLine(cur.line);
|
19
|
+
if (cur.ch && cur.ch < line.length &&
|
20
|
+
pairs.indexOf(line.slice(cur.ch - 1, cur.ch + 1)) % 2 == 0)
|
21
|
+
cm.replaceRange("", CodeMirror.Pos(cur.line, cur.ch - 1), CodeMirror.Pos(cur.line, cur.ch + 1));
|
22
|
+
else
|
23
|
+
return CodeMirror.Pass;
|
24
|
+
}
|
25
|
+
};
|
26
|
+
var closingBrackets = [];
|
27
|
+
for (var i = 0; i < pairs.length; i += 2) (function(left, right) {
|
28
|
+
if (left != right) closingBrackets.push(right);
|
29
|
+
function surround(cm) {
|
30
|
+
var selection = cm.getSelection();
|
31
|
+
cm.replaceSelection(left + selection + right);
|
32
|
+
}
|
33
|
+
function maybeOverwrite(cm) {
|
34
|
+
var cur = cm.getCursor(), ahead = cm.getRange(cur, CodeMirror.Pos(cur.line, cur.ch + 1));
|
35
|
+
if (ahead != right || cm.somethingSelected()) return CodeMirror.Pass;
|
36
|
+
else cm.execCommand("goCharRight");
|
37
|
+
}
|
38
|
+
map["'" + left + "'"] = function(cm) {
|
39
|
+
if (left == "'" && cm.getTokenAt(cm.getCursor()).type == "comment")
|
40
|
+
return CodeMirror.Pass;
|
41
|
+
if (cm.somethingSelected()) return surround(cm);
|
42
|
+
if (left == right && maybeOverwrite(cm) != CodeMirror.Pass) return;
|
43
|
+
var cur = cm.getCursor(), ahead = CodeMirror.Pos(cur.line, cur.ch + 1);
|
44
|
+
var line = cm.getLine(cur.line), nextChar = line.charAt(cur.ch);
|
45
|
+
if (line.length == cur.ch || closingBrackets.indexOf(nextChar) >= 0 || SPACE_CHAR_REGEX.test(nextChar))
|
46
|
+
cm.replaceSelection(left + right, {head: ahead, anchor: ahead});
|
47
|
+
else
|
48
|
+
return CodeMirror.Pass;
|
49
|
+
};
|
50
|
+
if (left != right) map["'" + right + "'"] = maybeOverwrite;
|
51
|
+
})(pairs.charAt(i), pairs.charAt(i + 1));
|
52
|
+
return map;
|
53
|
+
}
|
54
|
+
})();
|
@@ -27,9 +27,9 @@
|
|
27
27
|
if (val && (old == CodeMirror.Init || !old)) {
|
28
28
|
var map = {name: "autoCloseTags"};
|
29
29
|
if (typeof val != "object" || val.whenClosing)
|
30
|
-
map["'/'"] = function(cm) { autoCloseTag(cm, '/'); };
|
30
|
+
map["'/'"] = function(cm) { return autoCloseTag(cm, '/'); };
|
31
31
|
if (typeof val != "object" || val.whenOpening)
|
32
|
-
map["'>'"] = function(cm) { autoCloseTag(cm, '>'); };
|
32
|
+
map["'>'"] = function(cm) { return autoCloseTag(cm, '>'); };
|
33
33
|
cm.addKeyMap(map);
|
34
34
|
} else if (!val && (old != CodeMirror.Init && old)) {
|
35
35
|
cm.removeKeyMap("autoCloseTags");
|
@@ -44,7 +44,7 @@
|
|
44
44
|
function autoCloseTag(cm, ch) {
|
45
45
|
var pos = cm.getCursor(), tok = cm.getTokenAt(pos);
|
46
46
|
var inner = CodeMirror.innerMode(cm.getMode(), tok.state), state = inner.state;
|
47
|
-
if (inner.mode.name != "xml")
|
47
|
+
if (inner.mode.name != "xml") return CodeMirror.Pass;
|
48
48
|
|
49
49
|
var opt = cm.getOption("autoCloseTags"), html = inner.mode.configuration == "html";
|
50
50
|
var dontCloseTags = (typeof opt == "object" && opt.dontCloseTags) || (html && htmlDontClose);
|
@@ -56,24 +56,25 @@
|
|
56
56
|
var lowerTagName = tagName.toLowerCase();
|
57
57
|
// Don't process the '>' at the end of an end-tag or self-closing tag
|
58
58
|
if (tok.type == "tag" && state.type == "closeTag" ||
|
59
|
-
|
59
|
+
tok.string.indexOf("/") == (tok.string.length - 1) || // match something like <someTagName />
|
60
60
|
dontCloseTags && indexOf(dontCloseTags, lowerTagName) > -1)
|
61
|
-
|
61
|
+
return CodeMirror.Pass;
|
62
62
|
|
63
63
|
var doIndent = indentTags && indexOf(indentTags, lowerTagName) > -1;
|
64
|
+
var curPos = doIndent ? CodeMirror.Pos(pos.line + 1, 0) : CodeMirror.Pos(pos.line, pos.ch + 1);
|
64
65
|
cm.replaceSelection(">" + (doIndent ? "\n\n" : "") + "</" + tagName + ">",
|
65
|
-
|
66
|
+
{head: curPos, anchor: curPos});
|
66
67
|
if (doIndent) {
|
67
68
|
cm.indentLine(pos.line + 1);
|
68
69
|
cm.indentLine(pos.line + 2);
|
69
70
|
}
|
70
71
|
return;
|
71
|
-
} else if (ch == "/" && tok.
|
72
|
+
} else if (ch == "/" && tok.string == "<") {
|
72
73
|
var tagName = state.context && state.context.tagName;
|
73
74
|
if (tagName) cm.replaceSelection("/" + tagName + ">", "end");
|
74
75
|
return;
|
75
76
|
}
|
76
|
-
|
77
|
+
return CodeMirror.Pass;
|
77
78
|
}
|
78
79
|
|
79
80
|
function indexOf(collection, elt) {
|
@@ -5,14 +5,14 @@
|
|
5
5
|
blockCommentEnd: "*/",
|
6
6
|
blockCommentContinue: " * "});
|
7
7
|
|
8
|
-
|
8
|
+
function continueComment(cm) {
|
9
9
|
var pos = cm.getCursor(), token = cm.getTokenAt(pos);
|
10
10
|
var mode = CodeMirror.innerMode(cm.getMode(), token.state).mode;
|
11
11
|
var space;
|
12
12
|
|
13
13
|
if (token.type == "comment" && mode.blockCommentStart) {
|
14
14
|
var end = token.string.indexOf(mode.blockCommentEnd);
|
15
|
-
var full = cm.getRange(
|
15
|
+
var full = cm.getRange(CodeMirror.Pos(pos.line, 0), CodeMirror.Pos(pos.line, token.end)), found;
|
16
16
|
if (end != -1 && end == token.string.length - mode.blockCommentEnd.length) {
|
17
17
|
// Comment ended, don't continue it
|
18
18
|
} else if (token.string.indexOf(mode.blockCommentStart) == 0) {
|
@@ -31,6 +31,14 @@
|
|
31
31
|
if (space != null)
|
32
32
|
cm.replaceSelection("\n" + space + mode.blockCommentContinue, "end");
|
33
33
|
else
|
34
|
-
|
35
|
-
}
|
34
|
+
return CodeMirror.Pass;
|
35
|
+
}
|
36
|
+
|
37
|
+
CodeMirror.defineOption("continueComments", null, function(cm, val, prev) {
|
38
|
+
if (prev && prev != CodeMirror.Init)
|
39
|
+
cm.removeKeyMap("continueComment");
|
40
|
+
var map = {name: "continueComment"};
|
41
|
+
map[typeof val == "string" ? val : "Enter"] = continueComment;
|
42
|
+
cm.addKeyMap(map);
|
43
|
+
});
|
36
44
|
})();
|
@@ -0,0 +1,25 @@
|
|
1
|
+
(function() {
|
2
|
+
'use strict';
|
3
|
+
|
4
|
+
var listRE = /^(\s*)([*+-]|(\d+)\.)(\s*)/,
|
5
|
+
unorderedBullets = '*+-';
|
6
|
+
|
7
|
+
CodeMirror.commands.newlineAndIndentContinueMarkdownList = function(cm) {
|
8
|
+
var pos = cm.getCursor(),
|
9
|
+
inList = cm.getStateAfter(pos.line).list,
|
10
|
+
match;
|
11
|
+
|
12
|
+
if (!inList || !(match = cm.getLine(pos.line).match(listRE))) {
|
13
|
+
cm.execCommand('newlineAndIndent');
|
14
|
+
return;
|
15
|
+
}
|
16
|
+
|
17
|
+
var indent = match[1], after = match[4];
|
18
|
+
var bullet = unorderedBullets.indexOf(match[2]) >= 0
|
19
|
+
? match[2]
|
20
|
+
: (parseInt(match[3], 10) + 1) + '.';
|
21
|
+
|
22
|
+
cm.replaceSelection('\n' + indent + bullet + after, 'end');
|
23
|
+
};
|
24
|
+
|
25
|
+
}());
|
@@ -1,20 +1,29 @@
|
|
1
1
|
(function() {
|
2
|
+
var ie_lt8 = /MSIE \d/.test(navigator.userAgent) &&
|
3
|
+
(document.documentMode == null || document.documentMode < 8);
|
4
|
+
|
5
|
+
var Pos = CodeMirror.Pos;
|
6
|
+
|
2
7
|
var matching = {"(": ")>", ")": "(<", "[": "]>", "]": "[<", "{": "}>", "}": "{<"};
|
3
8
|
function findMatchingBracket(cm) {
|
9
|
+
var maxScanLen = cm.state._matchBrackets.maxScanLineLength || 10000;
|
10
|
+
|
4
11
|
var cur = cm.getCursor(), line = cm.getLineHandle(cur.line), pos = cur.ch - 1;
|
5
12
|
var match = (pos >= 0 && matching[line.text.charAt(pos)]) || matching[line.text.charAt(++pos)];
|
6
13
|
if (!match) return null;
|
7
14
|
var forward = match.charAt(1) == ">", d = forward ? 1 : -1;
|
8
|
-
var style = cm.getTokenAt(
|
15
|
+
var style = cm.getTokenAt(Pos(cur.line, pos + 1)).type;
|
9
16
|
|
10
17
|
var stack = [line.text.charAt(pos)], re = /[(){}[\]]/;
|
11
18
|
function scan(line, lineNo, start) {
|
12
19
|
if (!line.text) return;
|
13
20
|
var pos = forward ? 0 : line.text.length - 1, end = forward ? line.text.length : -1;
|
21
|
+
if (line.text.length > maxScanLen) return null;
|
22
|
+
var checkTokenStyles = line.text.length < 1000;
|
14
23
|
if (start != null) pos = start + d;
|
15
24
|
for (; pos != end; pos += d) {
|
16
25
|
var ch = line.text.charAt(pos);
|
17
|
-
if (re.test(ch) && cm.getTokenAt(
|
26
|
+
if (re.test(ch) && (!checkTokenStyles || cm.getTokenAt(Pos(lineNo, pos + 1)).type == style)) {
|
18
27
|
var match = matching[ch];
|
19
28
|
if (match.charAt(1) == ">" == forward) stack.push(ch);
|
20
29
|
else if (stack.pop() != match.charAt(0)) return {pos: pos, match: false};
|
@@ -27,17 +36,23 @@
|
|
27
36
|
else found = scan(cm.getLineHandle(i), i);
|
28
37
|
if (found) break;
|
29
38
|
}
|
30
|
-
return {from:
|
39
|
+
return {from: Pos(cur.line, pos), to: found && Pos(i, found.pos), match: found && found.match};
|
31
40
|
}
|
32
41
|
|
33
42
|
function matchBrackets(cm, autoclear) {
|
43
|
+
// Disable brace matching in long lines, since it'll cause hugely slow updates
|
44
|
+
var maxHighlightLen = cm.state._matchBrackets.maxHighlightLineLength || 1000;
|
34
45
|
var found = findMatchingBracket(cm);
|
35
|
-
if (!found)
|
46
|
+
if (!found || cm.getLine(found.from.line).length > maxHighlightLen ||
|
47
|
+
found.to && cm.getLine(found.to.line).length > maxHighlightLen)
|
48
|
+
return;
|
49
|
+
|
36
50
|
var style = found.match ? "CodeMirror-matchingbracket" : "CodeMirror-nonmatchingbracket";
|
37
|
-
var one = cm.markText(found.from,
|
38
|
-
|
39
|
-
|
40
|
-
|
51
|
+
var one = cm.markText(found.from, Pos(found.from.line, found.from.ch + 1), {className: style});
|
52
|
+
var two = found.to && cm.markText(found.to, Pos(found.to.line, found.to.ch + 1), {className: style});
|
53
|
+
// Kludge to work around the IE bug from issue #1193, where text
|
54
|
+
// input stops going to the textare whever this fires.
|
55
|
+
if (ie_lt8 && cm.state.focused) cm.display.input.focus();
|
41
56
|
var clear = function() {
|
42
57
|
cm.operation(function() { one.clear(); two && two.clear(); });
|
43
58
|
};
|
@@ -53,9 +68,13 @@
|
|
53
68
|
});
|
54
69
|
}
|
55
70
|
|
56
|
-
CodeMirror.defineOption("matchBrackets", false, function(cm, val) {
|
57
|
-
if (
|
58
|
-
|
71
|
+
CodeMirror.defineOption("matchBrackets", false, function(cm, val, old) {
|
72
|
+
if (old && old != CodeMirror.Init)
|
73
|
+
cm.off("cursorActivity", doMatchBrackets);
|
74
|
+
if (val) {
|
75
|
+
cm.state._matchBrackets = typeof val == "object" ? val : {};
|
76
|
+
cm.on("cursorActivity", doMatchBrackets);
|
77
|
+
}
|
59
78
|
});
|
60
79
|
|
61
80
|
CodeMirror.defineExtension("matchBrackets", function() {matchBrackets(this, true);});
|
@@ -0,0 +1,31 @@
|
|
1
|
+
CodeMirror.braceRangeFinder = function(cm, start) {
|
2
|
+
var line = start.line, lineText = cm.getLine(line);
|
3
|
+
var at = lineText.length, startChar, tokenType;
|
4
|
+
for (; at > 0;) {
|
5
|
+
var found = lineText.lastIndexOf("{", at);
|
6
|
+
if (found < start.ch) break;
|
7
|
+
tokenType = cm.getTokenAt(CodeMirror.Pos(line, found + 1)).type;
|
8
|
+
if (!/^(comment|string)/.test(tokenType)) { startChar = found; break; }
|
9
|
+
at = found - 1;
|
10
|
+
}
|
11
|
+
if (startChar == null || lineText.lastIndexOf("}") > startChar) return;
|
12
|
+
var count = 1, lastLine = cm.lineCount(), end, endCh;
|
13
|
+
outer: for (var i = line + 1; i < lastLine; ++i) {
|
14
|
+
var text = cm.getLine(i), pos = 0;
|
15
|
+
for (;;) {
|
16
|
+
var nextOpen = text.indexOf("{", pos), nextClose = text.indexOf("}", pos);
|
17
|
+
if (nextOpen < 0) nextOpen = text.length;
|
18
|
+
if (nextClose < 0) nextClose = text.length;
|
19
|
+
pos = Math.min(nextOpen, nextClose);
|
20
|
+
if (pos == text.length) break;
|
21
|
+
if (cm.getTokenAt(CodeMirror.Pos(i, pos + 1)).type == tokenType) {
|
22
|
+
if (pos == nextOpen) ++count;
|
23
|
+
else if (!--count) { end = i; endCh = pos; break outer; }
|
24
|
+
}
|
25
|
+
++pos;
|
26
|
+
}
|
27
|
+
}
|
28
|
+
if (end == null || end == line + 1) return;
|
29
|
+
return {from: CodeMirror.Pos(line, startChar + 1),
|
30
|
+
to: CodeMirror.Pos(end, endCh)};
|
31
|
+
};
|
@@ -0,0 +1,32 @@
|
|
1
|
+
CodeMirror.newFoldFunction = function(rangeFinder, widget) {
|
2
|
+
if (widget == null) widget = "\u2194";
|
3
|
+
if (typeof widget == "string") {
|
4
|
+
var text = document.createTextNode(widget);
|
5
|
+
widget = document.createElement("span");
|
6
|
+
widget.appendChild(text);
|
7
|
+
widget.className = "CodeMirror-foldmarker";
|
8
|
+
}
|
9
|
+
|
10
|
+
return function(cm, pos) {
|
11
|
+
if (typeof pos == "number") pos = CodeMirror.Pos(pos, 0);
|
12
|
+
var range = rangeFinder(cm, pos);
|
13
|
+
if (!range) return;
|
14
|
+
|
15
|
+
var present = cm.findMarksAt(range.from), cleared = 0;
|
16
|
+
for (var i = 0; i < present.length; ++i) {
|
17
|
+
if (present[i].__isFold) {
|
18
|
+
++cleared;
|
19
|
+
present[i].clear();
|
20
|
+
}
|
21
|
+
}
|
22
|
+
if (cleared) return;
|
23
|
+
|
24
|
+
var myWidget = widget.cloneNode(true);
|
25
|
+
CodeMirror.on(myWidget, "mousedown", function() {myRange.clear();});
|
26
|
+
var myRange = cm.markText(range.from, range.to, {
|
27
|
+
replacedWith: myWidget,
|
28
|
+
clearOnEnter: true,
|
29
|
+
__isFold: true
|
30
|
+
});
|
31
|
+
};
|
32
|
+
};
|
@@ -0,0 +1,11 @@
|
|
1
|
+
CodeMirror.indentRangeFinder = function(cm, start) {
|
2
|
+
var tabSize = cm.getOption("tabSize"), firstLine = cm.getLine(start.line);
|
3
|
+
var myIndent = CodeMirror.countColumn(firstLine, null, tabSize);
|
4
|
+
for (var i = start.line + 1, end = cm.lineCount(); i < end; ++i) {
|
5
|
+
var curLine = cm.getLine(i);
|
6
|
+
if (CodeMirror.countColumn(curLine, null, tabSize) < myIndent &&
|
7
|
+
CodeMirror.countColumn(cm.getLine(i-1), null, tabSize) > myIndent)
|
8
|
+
return {from: CodeMirror.Pos(start.line, firstLine.length),
|
9
|
+
to: CodeMirror.Pos(i, curLine.length)};
|
10
|
+
}
|
11
|
+
};
|
@@ -0,0 +1,64 @@
|
|
1
|
+
CodeMirror.tagRangeFinder = (function() {
|
2
|
+
var nameStartChar = "A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD";
|
3
|
+
var nameChar = nameStartChar + "\-\:\.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040";
|
4
|
+
var xmlTagStart = new RegExp("<(/?)([" + nameStartChar + "][" + nameChar + "]*)", "g");
|
5
|
+
|
6
|
+
return function(cm, start) {
|
7
|
+
var line = start.line, ch = start.ch, lineText = cm.getLine(line);
|
8
|
+
|
9
|
+
function nextLine() {
|
10
|
+
if (line >= cm.lastLine()) return;
|
11
|
+
ch = 0;
|
12
|
+
lineText = cm.getLine(++line);
|
13
|
+
return true;
|
14
|
+
}
|
15
|
+
function toTagEnd() {
|
16
|
+
for (;;) {
|
17
|
+
var gt = lineText.indexOf(">", ch);
|
18
|
+
if (gt == -1) { if (nextLine()) continue; else return; }
|
19
|
+
var lastSlash = lineText.lastIndexOf("/", gt);
|
20
|
+
var selfClose = lastSlash > -1 && /^\s*$/.test(lineText.slice(lastSlash + 1, gt));
|
21
|
+
ch = gt + 1;
|
22
|
+
return selfClose ? "selfClose" : "regular";
|
23
|
+
}
|
24
|
+
}
|
25
|
+
function toNextTag() {
|
26
|
+
for (;;) {
|
27
|
+
xmlTagStart.lastIndex = ch;
|
28
|
+
var found = xmlTagStart.exec(lineText);
|
29
|
+
if (!found) { if (nextLine()) continue; else return; }
|
30
|
+
ch = found.index + found[0].length;
|
31
|
+
return found;
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
var stack = [], startCh;
|
36
|
+
for (;;) {
|
37
|
+
var openTag = toNextTag(), end;
|
38
|
+
if (!openTag || line != start.line || !(end = toTagEnd())) return;
|
39
|
+
if (!openTag[1] && end != "selfClose") {
|
40
|
+
stack.push(openTag[2]);
|
41
|
+
startCh = ch;
|
42
|
+
break;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
for (;;) {
|
47
|
+
var next = toNextTag(), end, tagLine = line, tagCh = ch - (next ? next[0].length : 0);
|
48
|
+
if (!next || !(end = toTagEnd())) return;
|
49
|
+
if (end == "selfClose") continue;
|
50
|
+
if (next[1]) { // closing tag
|
51
|
+
for (var i = stack.length - 1; i >= 0; --i) if (stack[i] == next[2]) {
|
52
|
+
stack.length = i;
|
53
|
+
break;
|
54
|
+
}
|
55
|
+
if (!stack.length) return {
|
56
|
+
from: CodeMirror.Pos(start.line, startCh),
|
57
|
+
to: CodeMirror.Pos(tagLine, tagCh)
|
58
|
+
};
|
59
|
+
} else { // opening tag
|
60
|
+
stack.push(next[2]);
|
61
|
+
}
|
62
|
+
}
|
63
|
+
};
|
64
|
+
})();
|