0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 20:42:43 +00:00

Reduce duplicate code

This commit is contained in:
Trevor Buckner
2020-10-28 22:25:25 -04:00
parent 19c04e125a
commit e23120a4c6

View File

@@ -45,23 +45,19 @@ const CodeEditor = createClass({
makeBold : function() {
const selection = this.codeMirror.getSelection();
this.codeMirror.replaceSelection(`**${selection}**`, 'around');
if(selection.length === 0){
this.codeMirror.replaceSelection(`**${selection}**`, 'around');
const cursor = this.codeMirror.getCursor();
this.codeMirror.setCursor({ line: cursor.line, ch: cursor.ch - 2 });
} else {
this.codeMirror.replaceSelection(`**${selection}**`, 'around');
}
},
makeItalic : function() {
const selection = this.codeMirror.getSelection();
this.codeMirror.replaceSelection(`*${selection}*`, 'around');
if(selection.length === 0){
this.codeMirror.replaceSelection(`*${selection}*`, 'around');
const cursor = this.codeMirror.getCursor();
this.codeMirror.setCursor({ line: cursor.line, ch: cursor.ch - 1 });
} else {
this.codeMirror.replaceSelection(`*${selection}*`, 'around');
}
},