mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-11-23 23:06:54 +00:00
Updated makeBold and makeItalic functions to center cursor when selection is empty
This commit is contained in:
1 parent
6c813ddab1
commit
8a13387874
1 file changed
+15
-3
@@ -45,12 +45,24 @@ const CodeEditor = createClass({
|
||||
|
||||
makeBold : function() {
|
||||
const selection = this.codeMirror.getSelection();
|
||||
this.codeMirror.replaceSelection(`**${selection}**`, 'around');
|
||||
if (selection.length === 0){
|
||||
this.codeMirror.replaceSelection(`**${selection}**`, 'around');
|
||||
let 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');
|
||||
let cursor = this.codeMirror.getCursor();
|
||||
this.codeMirror.setCursor({ line: cursor.line, ch: cursor.ch - 1 });
|
||||
} else {
|
||||
this.codeMirror.replaceSelection(`*${selection}*`, 'around');
|
||||
}
|
||||
},
|
||||
|
||||
componentWillReceiveProps : function(nextProps){
|
||||
|
||||
Reference in new issue
Block a user