From ca9a8173bd51c8994033a107ccbb8c8b67a31aea Mon Sep 17 00:00:00 2001 From: Gazook89 <58999374+Gazook89@users.noreply.github.com> Date: Sat, 7 Aug 2021 22:43:15 -0500 Subject: [PATCH] Add HTML Comment Hotkey Resubmission of #1492 from new clone (old clone was deleted). --- .../editor/snippetbar/snippets/snippets.js | 7 +++++++ .../snippetbar/snippetsLegacy/snippets.js | 7 +++++++ shared/naturalcrit/codeEditor/codeEditor.jsx | 17 +++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/client/homebrew/editor/snippetbar/snippets/snippets.js b/client/homebrew/editor/snippetbar/snippets/snippets.js index 2ac8c7ea0..99226832d 100644 --- a/client/homebrew/editor/snippetbar/snippets/snippets.js +++ b/client/homebrew/editor/snippetbar/snippets/snippets.js @@ -113,6 +113,13 @@ module.exports = [ ' }\n' + '' }, + { + name : 'Add Comment', + icon : 'fas fa-comment-code', /* might need to be fa-solid fa-comment-code --not sure, Gazook */ + gen : dedent`\n + + \n` + }, ] }, diff --git a/client/homebrew/editor/snippetbar/snippetsLegacy/snippets.js b/client/homebrew/editor/snippetbar/snippetsLegacy/snippets.js index 2d4e2d0e4..830e5d194 100644 --- a/client/homebrew/editor/snippetbar/snippetsLegacy/snippets.js +++ b/client/homebrew/editor/snippetbar/snippetsLegacy/snippets.js @@ -100,6 +100,13 @@ module.exports = [ ' }\n' + '' }, + { + name : 'Add Comment', + icon : 'fas fa-comment-code', /* might need to be fa-solid fa-comment-code --not sure, Gazook */ + gen : dedent`\n + + \n` + }, ] }, diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx index a40c48436..6de06cf81 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -53,6 +53,14 @@ const CodeEditor = createClass({ 'Cmd-I' : this.makeItalic, 'Ctrl-M' : this.makeSpan, 'Cmd-M' : this.makeSpan, + '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, } }); @@ -88,6 +96,15 @@ const CodeEditor = createClass({ } }, + makeComment : function() { + const selection = this.codeMirror.getSelection(), t = selection.slice(0, 4) === ''; + this.codeMirror.replaceSelection(t ? selection.slice(4, -3) : ``, 'around'); + if(selection.length === 0){ + const cursor = this.codeMirror.getCursor(); + this.codeMirror.setCursor({ line: cursor.line, ch: cursor.ch - 3 }); + } + }, + //=-- Externally used -==// setCursorPosition : function(line, char){ setTimeout(()=>{