From 8a133878746bfa40be19913754919cdb9c3a0568 Mon Sep 17 00:00:00 2001 From: Rodrigo Kuerten Date: Mon, 26 Oct 2020 22:49:09 -0300 Subject: [PATCH 1/3] Updated makeBold and makeItalic functions to center cursor when selection is empty --- shared/naturalcrit/codeEditor/codeEditor.jsx | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx index 26ec17be5..603456d10 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -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){ From 19c04e125aec725fa6b0025cb0ab3666c6387ea8 Mon Sep 17 00:00:00 2001 From: Rodrigo Kuerten Date: Mon, 26 Oct 2020 23:09:36 -0300 Subject: [PATCH 2/3] Linting? --- shared/naturalcrit/codeEditor/codeEditor.jsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx index 603456d10..3b59d256a 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -45,20 +45,20 @@ const CodeEditor = createClass({ makeBold : function() { const selection = this.codeMirror.getSelection(); - if (selection.length === 0){ + if(selection.length === 0){ this.codeMirror.replaceSelection(`**${selection}**`, 'around'); - let cursor = this.codeMirror.getCursor(); + 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(); - if (selection.length === 0){ + if(selection.length === 0){ this.codeMirror.replaceSelection(`*${selection}*`, 'around'); - let cursor = this.codeMirror.getCursor(); + const cursor = this.codeMirror.getCursor(); this.codeMirror.setCursor({ line: cursor.line, ch: cursor.ch - 1 }); } else { this.codeMirror.replaceSelection(`*${selection}*`, 'around'); From e23120a4c68a8a967ed77c35d54707fcae0397c9 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Wed, 28 Oct 2020 22:25:25 -0400 Subject: [PATCH 3/3] Reduce duplicate code --- shared/naturalcrit/codeEditor/codeEditor.jsx | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx index 3b59d256a..e8d9cb69f 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -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'); } },