From ec2c74f09300bb3741d54c61c1f83333e023e3ad Mon Sep 17 00:00:00 2001 From: Rodrigo Kuerten Date: Tue, 21 Sep 2021 17:11:07 -0300 Subject: [PATCH 1/4] 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'); From bbad4b9e8ace3c0665adbeea209d6ddbf4b2e0c4 Mon Sep 17 00:00:00 2001 From: Rodrigo Kuerten Date: Tue, 21 Sep 2021 17:25:37 -0300 Subject: [PATCH 2/4] Removed H1 and H2 options and updated cursor after added hashtags --- shared/naturalcrit/codeEditor/codeEditor.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx index 368af3e9c..8b96f0d0f 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -55,8 +55,6 @@ const CodeEditor = createClass({ '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), @@ -73,6 +71,8 @@ const CodeEditor = createClass({ const selection = this.codeMirror.getSelection(); const header = Array(number).fill('#').join(''); this.codeMirror.replaceSelection(`${header} ${selection}`, 'around'); + const cursor = this.codeMirror.getCursor(); + this.codeMirror.setCursor({ line: cursor.line, ch: cursor.ch + selection.length + number + 1 }); }, makeBold : function() { From c10bdabee0d057c3aa315cec09c9008ffa5e8c2a Mon Sep 17 00:00:00 2001 From: Rodrigo Kuerten Date: Wed, 22 Sep 2021 18:21:34 -0300 Subject: [PATCH 3/4] Added h1 and h2 & cmd version --- shared/naturalcrit/codeEditor/codeEditor.jsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx index 8b96f0d0f..9c506a020 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -55,10 +55,18 @@ const CodeEditor = createClass({ '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), + 'Shift-Cmd-1' : ()=>this.makeHeader(1), + 'Shift-Cmd-2' : ()=>this.makeHeader(2), + 'Shift-Cmd-3' : ()=>this.makeHeader(3), + 'Shift-Cmd-4' : ()=>this.makeHeader(4), + 'Shift-Cmd-5' : ()=>this.makeHeader(5), + 'Shift-Cmd-6' : ()=>this.makeHeader(6), } }); From 1865e56b04ee49cbd330de8fe72e2602d005d1fb Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Thu, 2 Dec 2021 23:44:48 -0500 Subject: [PATCH 4/4] lint --- shared/naturalcrit/codeEditor/codeEditor.jsx | 24 ++++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx index d21a3c256..95302b10d 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -95,18 +95,18 @@ const CodeEditor = createClass({ 'Cmd-/' : this.makeComment, 'Ctrl-K' : this.makeLink, 'Cmd-K' : this.makeLink, - '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), - 'Shift-Cmd-1' : ()=>this.makeHeader(1), - 'Shift-Cmd-2' : ()=>this.makeHeader(2), - 'Shift-Cmd-3' : ()=>this.makeHeader(3), - 'Shift-Cmd-4' : ()=>this.makeHeader(4), - 'Shift-Cmd-5' : ()=>this.makeHeader(5), - 'Shift-Cmd-6' : ()=>this.makeHeader(6), + '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), + 'Shift-Cmd-1' : ()=>this.makeHeader(1), + 'Shift-Cmd-2' : ()=>this.makeHeader(2), + 'Shift-Cmd-3' : ()=>this.makeHeader(3), + 'Shift-Cmd-4' : ()=>this.makeHeader(4), + 'Shift-Cmd-5' : ()=>this.makeHeader(5), + 'Shift-Cmd-6' : ()=>this.makeHeader(6), 'Shift-Ctrl-Enter' : this.newColumn, 'Shift-Cmd-Enter' : this.newColumn, 'Ctrl-Enter' : this.newPage,