Merge branch '2.0'
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / js / 3rdParty / codemirror / addon / edit / continuelist.js
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) {
9 "use strict";
10
11 var listRE = /^(\s*)([*+-]|(\d+)\.)(\s*)/,
12 unorderedBullets = "*+-";
13
14 CodeMirror.commands.newlineAndIndentContinueMarkdownList = function(cm) {
15 if (cm.getOption("disableInput")) return CodeMirror.Pass;
16 var ranges = cm.listSelections(), replacements = [];
17 for (var i = 0; i < ranges.length; i++) {
18 var pos = ranges[i].head, match;
19 var inList = cm.getStateAfter(pos.line).list !== false;
20
21 if (!ranges[i].empty() || !inList || !(match = cm.getLine(pos.line).match(listRE))) {
22 cm.execCommand("newlineAndIndent");
23 return;
24 }
25 var indent = match[1], after = match[4];
26 var bullet = unorderedBullets.indexOf(match[2]) >= 0
27 ? match[2]
28 : (parseInt(match[3], 10) + 1) + ".";
29
30 replacements[i] = "\n" + indent + bullet + after;
31 }
32
33 cm.replaceSelections(replacements);
34 };
35 });