Merge branch '2.0'
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / js / 3rdParty / codemirror / addon / edit / continuelist.js
CommitLineData
837afb80
TD
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";
77b7b761
TD
10
11 var listRE = /^(\s*)([*+-]|(\d+)\.)(\s*)/,
837afb80 12 unorderedBullets = "*+-";
77b7b761
TD
13
14 CodeMirror.commands.newlineAndIndentContinueMarkdownList = function(cm) {
837afb80
TD
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;
77b7b761 20
837afb80
TD
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) + ".";
77b7b761 29
837afb80
TD
30 replacements[i] = "\n" + indent + bullet + after;
31 }
77b7b761 32
837afb80 33 cm.replaceSelections(replacements);
77b7b761 34 };
837afb80 35});