0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 20:42:43 +00:00

add comment about trying capture groups in future.

This commit is contained in:
Gazook89
2021-09-23 01:01:02 -05:00
parent beb3c7ec89
commit b3e37dd2c1

View File

@@ -105,8 +105,8 @@ const CodeEditor = createClass({
const isLink = /^\[(.*)(\]\()(.*)\)$/g;
const selection = this.codeMirror.getSelection();
if(isLink.test(selection) == true){
const altText = selection.slice(1, selection.lastIndexOf(']('));
const url = selection.slice(selection.lastIndexOf('](') + 2, -1);
const altText = selection.slice(1, selection.lastIndexOf('](')); // could likely be done better with capture groups
const url = selection.slice(selection.lastIndexOf('](') + 2, -1); // could likely be done better with capture groups
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 });