mirror of
https://github.com/Ionaru/easy-markdown-editor
synced 2025-07-07 01:54:27 -06:00
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
This commit is contained in:
commit
1e9e4e46e0
@ -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…
x
Reference in New Issue
Block a user