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:
parent
e980c146ff
commit
dfc7224fc7
2 changed files with 11 additions and 4 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue