From ec2c74f09300bb3741d54c61c1f83333e023e3ad Mon Sep 17 00:00:00 2001 From: Rodrigo Kuerten Date: Tue, 21 Sep 2021 17:11:07 -0300 Subject: [PATCH] Created base make header functions --- shared/naturalcrit/codeEditor/codeEditor.jsx | 28 ++++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx index 9707bde56..368af3e9c 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -47,14 +47,20 @@ 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-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-M' : this.makeSpan, + 'Cmd-M' : this.makeSpan, + 'Ctrl-/' : this.makeComment, + 'Cmd-/' : this.makeComment, + 'Shift-Ctrl-1' : ()=>this.makeHeader(1), + 'Shift-Ctrl-2' : ()=>this.makeHeader(2), + 'Shift-Ctrl-3' : ()=>this.makeHeader(3), + 'Shift-Ctrl-4' : ()=>this.makeHeader(4), + 'Shift-Ctrl-5' : ()=>this.makeHeader(5), + 'Shift-Ctrl-6' : ()=>this.makeHeader(6), } }); @@ -63,6 +69,12 @@ const CodeEditor = createClass({ this.updateSize(); }, + makeHeader : function (number) { + const selection = this.codeMirror.getSelection(); + const header = Array(number).fill('#').join(''); + this.codeMirror.replaceSelection(`${header} ${selection}`, 'around'); + }, + makeBold : function() { const selection = this.codeMirror.getSelection(), t = selection.slice(0, 2) === '**' && selection.slice(-2) === '**'; this.codeMirror.replaceSelection(t ? selection.slice(2, -2) : `**${selection}**`, 'around');