mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-11 09:02:44 +00:00
Merge pull request #1568 from Gazook89/Hotkey-for-Links
Hotkey for hyperlinks (`Ctrl`/`Cmd` + `K`)
This commit is contained in:
@@ -82,6 +82,8 @@ const CodeEditor = createClass({
|
|||||||
'Cmd-M' : this.makeSpan,
|
'Cmd-M' : this.makeSpan,
|
||||||
'Ctrl-/' : this.makeComment,
|
'Ctrl-/' : this.makeComment,
|
||||||
'Cmd-/' : this.makeComment,
|
'Cmd-/' : this.makeComment,
|
||||||
|
'Ctrl-K' : this.makeLink,
|
||||||
|
'Cmd-K' : this.makeLink,
|
||||||
'Ctrl-[' : this.foldAllCode,
|
'Ctrl-[' : this.foldAllCode,
|
||||||
'Cmd-[' : this.foldAllCode,
|
'Cmd-[' : this.foldAllCode,
|
||||||
'Ctrl-]' : this.unfoldAllCode,
|
'Ctrl-]' : this.unfoldAllCode,
|
||||||
@@ -153,6 +155,23 @@ const CodeEditor = createClass({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
makeLink : function() {
|
||||||
|
const isLink = /^\[(.*)\]\((.*)\)$/;
|
||||||
|
const selection = this.codeMirror.getSelection().trim();
|
||||||
|
let match;
|
||||||
|
if(match = isLink.exec(selection)){
|
||||||
|
const altText = match[1];
|
||||||
|
const url = match[2];
|
||||||
|
this.codeMirror.replaceSelection(`${altText} ${url}`);
|
||||||
|
const cursor = this.codeMirror.getCursor();
|
||||||
|
this.codeMirror.setSelection({ line: cursor.line, ch: cursor.ch - url.length }, { line: cursor.line, ch: cursor.ch });
|
||||||
|
} else {
|
||||||
|
this.codeMirror.replaceSelection(`[${selection || 'alt text'}](url)`);
|
||||||
|
const cursor = this.codeMirror.getCursor();
|
||||||
|
this.codeMirror.setSelection({ line: cursor.line, ch: cursor.ch - 4 }, { line: cursor.line, ch: cursor.ch - 1 });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
foldAllCode : function() {
|
foldAllCode : function() {
|
||||||
this.codeMirror.execCommand('foldAll');
|
this.codeMirror.execCommand('foldAll');
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user