mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-14 19:22:52 +00:00
refine removal of lists regardless if UL or OL
Next step after this is to get numbered lists to increase
This commit is contained in:
@@ -55,10 +55,10 @@ const CodeEditor = createClass({
|
|||||||
'Cmd-M' : this.makeSpan,
|
'Cmd-M' : this.makeSpan,
|
||||||
'Ctrl-/' : this.makeComment,
|
'Ctrl-/' : this.makeComment,
|
||||||
'Cmd-/' : this.makeComment,
|
'Cmd-/' : this.makeComment,
|
||||||
'Ctrl-L' : this.makeUnOrderedList,
|
'Ctrl-L' : ()=>this.makeList('UL'),
|
||||||
'Cmd-L' : this.makeUnOrderedList,
|
'Cmd-L' : ()=>this.makeList('UL'),
|
||||||
'Shift-Ctrl-L' : this.makeOrderedList,
|
'Shift-Ctrl-L' : ()=>this.makeList('OL'),
|
||||||
'Shift-Cmd-L' : this.makeOrderedList
|
'Shift-Cmd-L' : ()=>this.makeList('OL')
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -103,19 +103,21 @@ const CodeEditor = createClass({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
makeUnOrderedList : function() {
|
makeList : function(listType) {
|
||||||
const selectionStart = this.codeMirror.getCursor('from');
|
const selectionStart = this.codeMirror.getCursor('from'), selectionEnd = this.codeMirror.getCursor('to');
|
||||||
const selectionEnd = this.codeMirror.getCursor('to');
|
|
||||||
this.codeMirror.setSelection(
|
this.codeMirror.setSelection(
|
||||||
{ line: selectionStart.line, ch: 0 },
|
{ line: selectionStart.line, ch: 0 },
|
||||||
{ line: selectionEnd.line, ch: this.codeMirror.getLine(selectionEnd.line).length }
|
{ line: selectionEnd.line, ch: this.codeMirror.getLine(selectionEnd.line).length }
|
||||||
);
|
);
|
||||||
const isUL = /^-\s/gm;
|
|
||||||
const newSelection = this.codeMirror.getSelection();
|
const newSelection = this.codeMirror.getSelection();
|
||||||
if(newSelection.match(isUL) == null){
|
|
||||||
this.codeMirror.replaceSelection(newSelection.replace(/^/gm, '- '), 'around');
|
const regex = /^\d+\.\s|^-\s/gm;
|
||||||
} else {
|
console.log(regex);
|
||||||
this.codeMirror.replaceSelection(newSelection.replace(isUL, ''), 'around');
|
if(newSelection.match(regex) != null){ // if selection IS A LIST
|
||||||
|
this.codeMirror.replaceSelection(newSelection.replace(regex, ''), 'around');
|
||||||
|
} else { // if selection IS NOT A LIST
|
||||||
|
listType == 'UL' ? this.codeMirror.replaceSelection(newSelection.replace(/^/gm, '- '), 'around') :
|
||||||
|
this.codeMirror.replaceSelection(newSelection.replace(/^/gm, '1. '), 'around');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user