Jeroen Akkerman 5 years ago
commit c429efaff1

@ -126,7 +126,7 @@ function createToolbarButton(options, enableTooltips, shortcuts) {
if( options.name && options.name in shortcuts ){ if( options.name && options.name in shortcuts ){
bindings[options.name] = options.action; bindings[options.name] = options.action;
} }
if (options.title && enableTooltips) { if (options.title && enableTooltips) {
el.title = createTooltip(options.title, options.action, shortcuts); el.title = createTooltip(options.title, options.action, shortcuts);
@ -988,13 +988,27 @@ function _toggleLine(cm, name) {
var map = { var map = {
'quote': '>', 'quote': '>',
'unordered-list': '*', 'unordered-list': '*',
'ordered-list': 'd+.', 'ordered-list': '\\d+.',
}; };
var rt = new RegExp(map[name]); var rt = new RegExp(map[name]);
return char && rt.test(char); 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; var line = 1;
for (var i = startPoint.line; i <= endPoint.line; i++) { for (var i = startPoint.line; i <= endPoint.line; i++) {
(function (i) { (function (i) {
@ -1002,16 +1016,13 @@ function _toggleLine(cm, name) {
if (stat[name]) { if (stat[name]) {
text = text.replace(repl[name], '$1'); text = text.replace(repl[name], '$1');
} else { } else {
var arr = listRegexp.exec(text); // If we're toggling unordered-list formatting, check if the current line
var char = _getChar(name, line); // is part of an ordered-list, and if so, untoggle that first.
if (arr !== null) { // Workaround for https://github.com/Ionaru/easy-markdown-editor/issues/92
if (_checkChar(name, arr[2])) { if (name == 'unordered-list') {
char = ''; text = _toggle('ordered-list', text, true);
}
text = arr[1] + char + arr[3] + text.replace(whitespacesRegexp, '').replace(repl[name], '$1');
} else {
text = char + ' ' + text;
} }
text = _toggle(name, text, false);
line += 1; line += 1;
} }
cm.replaceRange(text, { cm.replaceRange(text, {
@ -1684,22 +1695,22 @@ EasyMDE.prototype.autosave = function () {
console.log('EasyMDE: You must set a uniqueId to use the autosave feature'); console.log('EasyMDE: You must set a uniqueId to use the autosave feature');
return; return;
} }
if(this.options.autosave.binded !== true) { if(this.options.autosave.binded !== true) {
if (easyMDE.element.form != null && easyMDE.element.form != undefined) { if (easyMDE.element.form != null && easyMDE.element.form != undefined) {
easyMDE.element.form.addEventListener('submit', function () { easyMDE.element.form.addEventListener('submit', function () {
clearTimeout(easyMDE.autosaveTimeoutId); clearTimeout(easyMDE.autosaveTimeoutId);
easyMDE.autosaveTimeoutId = undefined; easyMDE.autosaveTimeoutId = undefined;
localStorage.removeItem('smde_' + easyMDE.options.autosave.uniqueId); localStorage.removeItem('smde_' + easyMDE.options.autosave.uniqueId);
// Restart autosaving in case the submit will be cancelled down the line // Restart autosaving in case the submit will be cancelled down the line
setTimeout(function() { setTimeout(function() {
easyMDE.autosave(); easyMDE.autosave();
}, easyMDE.options.autosave.delay || 10000); }, easyMDE.options.autosave.delay || 10000);
}); });
} }
this.options.autosave.binded = true; this.options.autosave.binded = true;
} }

Loading…
Cancel
Save