Fixed time zone calculation issue
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / js / 3rdParty / codemirror / addon / edit / continuecomment.js
1 (function() {
2 var modes = ["clike", "css", "javascript"];
3 for (var i = 0; i < modes.length; ++i)
4 CodeMirror.extendMode(modes[i], {blockCommentStart: "/*",
5 blockCommentEnd: "*/",
6 blockCommentContinue: " * "});
7
8 function continueComment(cm) {
9 var pos = cm.getCursor(), token = cm.getTokenAt(pos);
10 var mode = CodeMirror.innerMode(cm.getMode(), token.state).mode;
11 var space;
12
13 if (token.type == "comment" && mode.blockCommentStart) {
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) {
17 // Comment ended, don't continue it
18 } else if (token.string.indexOf(mode.blockCommentStart) == 0) {
19 space = full.slice(0, token.start);
20 if (!/^\s*$/.test(space)) {
21 space = "";
22 for (var i = 0; i < token.start; ++i) space += " ";
23 }
24 } else if ((found = full.indexOf(mode.blockCommentContinue)) != -1 &&
25 found + mode.blockCommentContinue.length > token.start &&
26 /^\s*$/.test(full.slice(0, found))) {
27 space = full.slice(0, found);
28 }
29 }
30
31 if (space != null)
32 cm.replaceSelection("\n" + space + mode.blockCommentContinue, "end");
33 else
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 });
44 })();