Converting selected text to MD link when pasting a URL (#8242)

* Converting selected text to MD link when pasting a URL

* Update src/editor/operations.ts

Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>

* Converting selected text to MD link when pasting a URL

Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Sinharitik589 2022-05-09 11:04:56 +05:30 committed by GitHub
parent e980c146ff
commit dfc7224fc7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View file

@ -216,7 +216,7 @@ export function formatRangeAsCode(range: Range): void {
replaceRangeAndExpandSelection(range, parts);
}
export function formatRangeAsLink(range: Range) {
export function formatRangeAsLink(range: Range, text?: string) {
const { model } = range;
const { partCreator } = model;
const linkRegex = /\[(.*?)\]\(.*?\)/g;
@ -229,7 +229,7 @@ export function formatRangeAsLink(range: Range) {
replaceRangeAndAutoAdjustCaret(range, newParts, true, prefixLength, suffixLength);
} else {
// We set offset to -1 here so that the caret lands between the brackets
replaceRangeAndMoveCaret(range, [partCreator.plain("[" + range.text + "]" + "()")], -1);
replaceRangeAndMoveCaret(range, [partCreator.plain("[" + range.text + "]" + "(" + (text ?? "") + ")")], -1);
}
}