From 57eea5c69ff7c87816a317b081e87a5961a49043 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Sat, 20 May 2023 01:24:36 -0400 Subject: [PATCH 1/3] Custom function to use spaces for indent --- shared/naturalcrit/codeEditor/codeEditor.jsx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx index 245317910..b2d9e4d26 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -97,11 +97,13 @@ const CodeEditor = createClass({ this.codeMirror = CodeMirror(this.refs.editor, { lineNumbers : true, lineWrapping : this.props.wrap, - indentWithTabs : true, + indentWithTabs : false, tabSize : 2, historyEventDelay : 250, scrollPastEnd : true, extraKeys : { + 'Tab' : this.indent, + 'Shift-Tab' : this.dedent, 'Ctrl-B' : this.makeBold, 'Cmd-B' : this.makeBold, 'Ctrl-I' : this.makeItalic, @@ -171,6 +173,19 @@ const CodeEditor = createClass({ this.updateSize(); }, + indent : function () { + const cm = this.codeMirror; + if (cm.somethingSelected()) { + cm.execCommand('indentMore'); + } else { + cm.execCommand('insertSoftTab'); + } + }, + + dedent : function () { + this.codeMirror.execCommand('indentLess'); + }, + makeHeader : function (number) { const selection = this.codeMirror.getSelection(); const header = Array(number).fill('#').join(''); From 288b407e3e4ce681481e1da6cd58ffd83ba39b9f Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Sat, 20 May 2023 01:32:07 -0400 Subject: [PATCH 2/3] Turn off smartIndent --- shared/naturalcrit/codeEditor/codeEditor.jsx | 1 + 1 file changed, 1 insertion(+) diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx index b2d9e4d26..2b3aa0125 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -99,6 +99,7 @@ const CodeEditor = createClass({ lineWrapping : this.props.wrap, indentWithTabs : false, tabSize : 2, + smartIndent : false, historyEventDelay : 250, scrollPastEnd : true, extraKeys : { From ca34ca499d0679b466845cd380c0d39194797ee9 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Mon, 22 May 2023 22:40:18 -0400 Subject: [PATCH 3/3] Remove duplicate tabs --- 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 2b3aa0125..d127bfdd8 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -176,11 +176,11 @@ const CodeEditor = createClass({ indent : function () { const cm = this.codeMirror; - if (cm.somethingSelected()) { - cm.execCommand('indentMore'); - } else { - cm.execCommand('insertSoftTab'); - } + if (cm.somethingSelected()) { + cm.execCommand('indentMore'); + } else { + cm.execCommand('insertSoftTab'); + } }, dedent : function () {