Closed ericscheid closed 10 months ago
Try the ctrl k (or cmd k) hotkey for inserting a link. Is that what you expect the Link to Page snippet to do? If so, i assume it can be ported over quickly.
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 });
}
},
Actually maybe it is harder. The snippets are just text things, and the little JS involved is just for generating text strings. I'm not sure that it is good to conflate "plain text insertions" with "buttons that manipulate your existing text", it would be unexpected.
I do think that it would be valuable to have the "normal" toolbar of functions that you get in most WYSIWYG editors, with "Underline", "Bold", "Italic" and "add link", etc. But I think that is separate from text insertions.
Ah .. I see we do have a hot-key for insert link (ctrl-K), and it does the desired. For the life of me I couldn't remember if there was one, and the nearest thing was the Insert Link to Page snippet.
OK, don't change the insert snippet behaviour.
Your idea:
Currently, selecting the Insert Link to Page snippet inserts
[Click here](#p3) to go to page 3
. This will appear in front of the cursor or current selection.It would be more useful if the editor detects that some text is selected, and linkifies that text. Thus, selecting "some text" would insert
[some text](#p3)
, replacing the selection. (This is how inserting links in many editors work.)