fix: untoggle ordered-list items first when toggling unordered-list items (#93)

fix: untoggle ordered-list items first when toggling unordered-list items
Fixes #92
pull/95/head
Jeroen Akkerman 5 years ago committed by GitHub
commit 1e9e4e46e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -988,13 +988,27 @@ function _toggleLine(cm, name) {
var map = {
'quote': '>',
'unordered-list': '*',
'ordered-list': 'd+.',
'ordered-list': '\\d+.',
};
var rt = new RegExp(map[name]);
return char && rt.test(char);
};
var _toggle = function (name, text, untoggleOnly) {
var arr = listRegexp.exec(text);
var char = _getChar(name, line);
if (arr !== null) {
if (_checkChar(name, arr[2])) {
char = '';
}
text = arr[1] + char + arr[3] + text.replace(whitespacesRegexp, '').replace(repl[name], '$1');
} else if (untoggleOnly == false){
text = char + ' ' + text;
}
return text;
};
var line = 1;
for (var i = startPoint.line; i <= endPoint.line; i++) {
(function (i) {
@ -1002,16 +1016,13 @@ function _toggleLine(cm, name) {
if (stat[name]) {
text = text.replace(repl[name], '$1');
} else {
var arr = listRegexp.exec(text);
var char = _getChar(name, line);
if (arr !== null) {
if (_checkChar(name, arr[2])) {
char = '';
}
text = arr[1] + char + arr[3] + text.replace(whitespacesRegexp, '').replace(repl[name], '$1');
} else {
text = char + ' ' + text;
// If we're toggling unordered-list formatting, check if the current line
// is part of an ordered-list, and if so, untoggle that first.
// Workaround for https://github.com/Ionaru/easy-markdown-editor/issues/92
if (name == 'unordered-list') {
text = _toggle('ordered-list', text, true);
}
text = _toggle(name, text, false);
line += 1;
}
cm.replaceRange(text, {

Loading…
Cancel
Save