From ba9413eae5d20d9be288fa7e41783f33e92be54a Mon Sep 17 00:00:00 2001 From: Gazook89 <58999374+Gazook89@users.noreply.github.com> Date: Mon, 27 Sep 2021 09:31:59 -0500 Subject: [PATCH 1/6] initial commit, add hotkey definitions --- shared/naturalcrit/codeEditor/codeEditor.jsx | 24 +++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx index 9707bde56..fe63f7565 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -47,14 +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-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, + 'Ctrl-L' : this.makeUnOrderedList, + 'Cmd-L' : this.makeUnOrderedList, + 'Shift-Ctrl-L' : this.makeOrderedList, + 'Shift-Cmd-L' : this.makeOrderedList } }); @@ -99,6 +103,10 @@ const CodeEditor = createClass({ } }, + makeUnOrderedList : function() { + const selection = this.codeMirror.getSelection() + } + //=-- Externally used -==// setCursorPosition : function(line, char){ setTimeout(()=>{ From cb0f5217fe734f11f106b3a76493d122a55ffb97 Mon Sep 17 00:00:00 2001 From: Gazook89 <58999374+Gazook89@users.noreply.github.com> Date: Mon, 27 Sep 2021 21:23:05 -0500 Subject: [PATCH 2/6] get and set selection to cover entire lines --- shared/naturalcrit/codeEditor/codeEditor.jsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx index fe63f7565..b641a403a 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -104,8 +104,20 @@ const CodeEditor = createClass({ }, makeUnOrderedList : function() { - const selection = this.codeMirror.getSelection() - } + const isList = /^-\s/gm; + const selectionStart = this.codeMirror.getCursor('from'); + const selectionEnd = this.codeMirror.getCursor('to'); + const selection = this.codeMirror.setSelection( + { line: selectionStart.line, ch: 0 }, + { line: selectionEnd.line, ch: this.codeMirror.getLine(selectionEnd.line).length }); + console.log(selectionStart, selectionEnd, selection); + }, + + + // ordered list: + // selection should expand to include the full line even if selection is only part of line + // regex should match "- " at beginning of selection + // regex should match "- " at beginnign of each line or maybe "\n- " //=-- Externally used -==// setCursorPosition : function(line, char){ From 41609f90ea4ddf66c1071f4acba286b864e2dded Mon Sep 17 00:00:00 2001 From: Gazook89 <58999374+Gazook89@users.noreply.github.com> Date: Mon, 27 Sep 2021 21:34:09 -0500 Subject: [PATCH 3/6] update to detect if an unordered list or not. --- shared/naturalcrit/codeEditor/codeEditor.jsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx index b641a403a..a91fda406 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -111,6 +111,11 @@ const CodeEditor = createClass({ { line: selectionStart.line, ch: 0 }, { line: selectionEnd.line, ch: this.codeMirror.getLine(selectionEnd.line).length }); console.log(selectionStart, selectionEnd, selection); + if(isList.test(this.codeMirror.getSelection()) == true){ + console.log('is list'); + } else { + console.log('is not a list'); + } }, From 6717692187c554b12945feb3b9a95ea8ed6b91f7 Mon Sep 17 00:00:00 2001 From: Gazook89 <58999374+Gazook89@users.noreply.github.com> Date: Tue, 28 Sep 2021 11:19:02 -0500 Subject: [PATCH 4/6] finish UL creation/removal function --- shared/naturalcrit/codeEditor/codeEditor.jsx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx index a91fda406..997143faf 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -104,17 +104,18 @@ const CodeEditor = createClass({ }, makeUnOrderedList : function() { - const isList = /^-\s/gm; const selectionStart = this.codeMirror.getCursor('from'); const selectionEnd = this.codeMirror.getCursor('to'); - const selection = this.codeMirror.setSelection( + this.codeMirror.setSelection( { line: selectionStart.line, ch: 0 }, - { line: selectionEnd.line, ch: this.codeMirror.getLine(selectionEnd.line).length }); - console.log(selectionStart, selectionEnd, selection); - if(isList.test(this.codeMirror.getSelection()) == true){ - console.log('is list'); + { line: selectionEnd.line, ch: this.codeMirror.getLine(selectionEnd.line).length } + ); + const isUL = /^-\s/gm; + const newSelection = this.codeMirror.getSelection(); + if(newSelection.match(isUL) == null){ + this.codeMirror.replaceSelection(newSelection.replace(/^/gm, '- '), 'around'); } else { - console.log('is not a list'); + this.codeMirror.replaceSelection(newSelection.replace(isUL, ''), 'around'); } }, From 63c59a223a67be9773fcc314b5abf499e385fb11 Mon Sep 17 00:00:00 2001 From: Gazook89 <58999374+Gazook89@users.noreply.github.com> Date: Tue, 28 Sep 2021 14:34:31 -0500 Subject: [PATCH 5/6] refine removal of lists regardless if UL or OL Next step after this is to get numbered lists to increase --- shared/naturalcrit/codeEditor/codeEditor.jsx | 26 +++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx index 997143faf..1ac90a124 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -55,10 +55,10 @@ const CodeEditor = createClass({ 'Cmd-M' : this.makeSpan, 'Ctrl-/' : this.makeComment, 'Cmd-/' : this.makeComment, - 'Ctrl-L' : this.makeUnOrderedList, - 'Cmd-L' : this.makeUnOrderedList, - 'Shift-Ctrl-L' : this.makeOrderedList, - 'Shift-Cmd-L' : this.makeOrderedList + 'Ctrl-L' : ()=>this.makeList('UL'), + 'Cmd-L' : ()=>this.makeList('UL'), + 'Shift-Ctrl-L' : ()=>this.makeList('OL'), + 'Shift-Cmd-L' : ()=>this.makeList('OL') } }); @@ -103,19 +103,21 @@ const CodeEditor = createClass({ } }, - makeUnOrderedList : function() { - const selectionStart = this.codeMirror.getCursor('from'); - const selectionEnd = this.codeMirror.getCursor('to'); + makeList : function(listType) { + const selectionStart = this.codeMirror.getCursor('from'), selectionEnd = this.codeMirror.getCursor('to'); this.codeMirror.setSelection( { line: selectionStart.line, ch: 0 }, { line: selectionEnd.line, ch: this.codeMirror.getLine(selectionEnd.line).length } ); - const isUL = /^-\s/gm; const newSelection = this.codeMirror.getSelection(); - if(newSelection.match(isUL) == null){ - this.codeMirror.replaceSelection(newSelection.replace(/^/gm, '- '), 'around'); - } else { - this.codeMirror.replaceSelection(newSelection.replace(isUL, ''), 'around'); + + const regex = /^\d+\.\s|^-\s/gm; + console.log(regex); + if(newSelection.match(regex) != null){ // if selection IS A LIST + this.codeMirror.replaceSelection(newSelection.replace(regex, ''), 'around'); + } else { // if selection IS NOT A LIST + listType == 'UL' ? this.codeMirror.replaceSelection(newSelection.replace(/^/gm, '- '), 'around') : + this.codeMirror.replaceSelection(newSelection.replace(/^/gm, '1. '), 'around'); } }, From 40a75b9b278e29996948374462a7afa87c95adc2 Mon Sep 17 00:00:00 2001 From: Gazook89 <58999374+Gazook89@users.noreply.github.com> Date: Tue, 28 Sep 2021 16:09:00 -0500 Subject: [PATCH 6/6] increment ordered list numbering --- shared/naturalcrit/codeEditor/codeEditor.jsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx index 1ac90a124..a48d451df 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -112,12 +112,16 @@ const CodeEditor = createClass({ const newSelection = this.codeMirror.getSelection(); const regex = /^\d+\.\s|^-\s/gm; - console.log(regex); if(newSelection.match(regex) != null){ // if selection IS A LIST this.codeMirror.replaceSelection(newSelection.replace(regex, ''), 'around'); } else { // if selection IS NOT A LIST - listType == 'UL' ? this.codeMirror.replaceSelection(newSelection.replace(/^/gm, '- '), 'around') : - this.codeMirror.replaceSelection(newSelection.replace(/^/gm, '1. '), 'around'); + listType == 'UL' ? this.codeMirror.replaceSelection(newSelection.replace(/^/gm, `- `), 'around') : + this.codeMirror.replaceSelection(newSelection.replace(/^/gm, (()=>{ + let n = 1; + return ()=>{ + return `${n++}. `; + }; + })()), 'around'); } },