0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-06 16:32:40 +00:00

Add HTML Comment Hotkey

Resubmission of #1492  from new clone (old clone was deleted).
This commit is contained in:
Gazook89
2021-08-07 22:43:15 -05:00
parent b98daed19c
commit ca9a8173bd
3 changed files with 31 additions and 0 deletions

View File

@@ -113,6 +113,13 @@ module.exports = [
' }\n' + ' }\n' +
'</style>' '</style>'
}, },
{
name : 'Add Comment',
icon : 'fas fa-comment-code', /* might need to be fa-solid fa-comment-code --not sure, Gazook */
gen : dedent`\n
<!-- Add a comment to your code here. Hotkey Ctrl/Cmd \\ -->
\n`
},
] ]
}, },

View File

@@ -100,6 +100,13 @@ module.exports = [
' }\n' + ' }\n' +
'</style>' '</style>'
}, },
{
name : 'Add Comment',
icon : 'fas fa-comment-code', /* might need to be fa-solid fa-comment-code --not sure, Gazook */
gen : dedent`\n
<!-- Add a comment to your code here. Hotkey Ctrl/Cmd \\ -->
\n`
},
] ]
}, },

View File

@@ -53,6 +53,14 @@ const CodeEditor = createClass({
'Cmd-I' : this.makeItalic, 'Cmd-I' : this.makeItalic,
'Ctrl-M' : this.makeSpan, 'Ctrl-M' : this.makeSpan,
'Cmd-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) === '<!--' && selection.slice(-3) === '-->';
this.codeMirror.replaceSelection(t ? selection.slice(4, -3) : `<!-- ${selection}-->`, 'around');
if(selection.length === 0){
const cursor = this.codeMirror.getCursor();
this.codeMirror.setCursor({ line: cursor.line, ch: cursor.ch - 3 });
}
},
//=-- Externally used -==// //=-- Externally used -==//
setCursorPosition : function(line, char){ setCursorPosition : function(line, char){
setTimeout(()=>{ setTimeout(()=>{