From 7dcd3356306632523c526cb4538ddfd06005dbf9 Mon Sep 17 00:00:00 2001 From: Gazook89 <58999374+Gazook89@users.noreply.github.com> Date: Mon, 6 Sep 2021 21:12:48 -0500 Subject: [PATCH] add makeDiv hotkey - V3 Curly Divs Shift-Cmd/Ctrl-M makes a curly div. --- shared/naturalcrit/codeEditor/codeEditor.jsx | 31 +++++++++++++------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx index f32a7e130..6858d5840 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -47,16 +47,18 @@ const CodeEditor = createClass({ indentWithTabs : true, tabSize : 2, extraKeys : { - 'Ctrl-B' : this.makeBold, - 'Cmd-B' : this.makeBold, - 'Ctrl-I' : this.makeItalic, - 'Cmd-I' : this.makeItalic, - 'Ctrl-U' : this.makeUnderline, - 'Cmd-U' : this.makeUnderline, - 'Ctrl-M' : this.makeSpan, - 'Cmd-M' : this.makeSpan, - 'Ctrl-/' : this.makeComment, - 'Cmd-/' : this.makeComment + 'Ctrl-B' : this.makeBold, + 'Cmd-B' : this.makeBold, + 'Ctrl-I' : this.makeItalic, + 'Cmd-I' : this.makeItalic, + 'Ctrl-U' : this.makeUnderline, + 'Cmd-U' : this.makeUnderline, + 'Ctrl-M' : this.makeSpan, + 'Cmd-M' : this.makeSpan, + 'Shift-Ctrl-M' : this.makeDiv, + 'Shift-Cmd-M' : this.makeDiv, + 'Ctrl-/' : this.makeComment, + 'Cmd-/' : this.makeComment } }); @@ -101,6 +103,15 @@ const CodeEditor = createClass({ } }, + makeDiv : function() { + const selection = this.codeMirror.getSelection(), t = selection.slice(0, 2) === '{{' && selection.slice(-2) === '}}'; + this.codeMirror.replaceSelection(t ? selection.slice(2, -2) : `{{\n${selection}\n}}`, 'around'); + if(selection.length === 0){ + const cursor = this.codeMirror.getCursor(); + this.codeMirror.setCursor({ line: cursor.line - 1, ch: cursor.ch }); // set to -2? if wanting to enter classes etc. if so, get rid of first \n when replacing selection + } + }, + makeComment : function() { const selection = this.codeMirror.getSelection(), t = selection.slice(0, 4) === ''; this.codeMirror.replaceSelection(t ? selection.slice(4, -3) : ``, 'around');