Fix regression around pasting links (#8537)
* Fix regression around pasting links * Add tests
This commit is contained in:
parent
7e21be06d0
commit
674aec4050
6 changed files with 163 additions and 29 deletions
|
@ -219,14 +219,12 @@ export function formatRangeAsCode(range: Range): void {
|
|||
export function formatRangeAsLink(range: Range, text?: string) {
|
||||
const { model } = range;
|
||||
const { partCreator } = model;
|
||||
const linkRegex = /\[(.*?)\]\(.*?\)/g;
|
||||
const linkRegex = /\[(.*?)]\(.*?\)/g;
|
||||
const isFormattedAsLink = linkRegex.test(range.text);
|
||||
if (isFormattedAsLink) {
|
||||
const linkDescription = range.text.replace(linkRegex, "$1");
|
||||
const newParts = [partCreator.plain(linkDescription)];
|
||||
const prefixLength = 1;
|
||||
const suffixLength = range.length - (linkDescription.length + 2);
|
||||
replaceRangeAndAutoAdjustCaret(range, newParts, true, prefixLength, suffixLength);
|
||||
replaceRangeAndMoveCaret(range, newParts, 0);
|
||||
} else {
|
||||
// We set offset to -1 here so that the caret lands between the brackets
|
||||
replaceRangeAndMoveCaret(range, [partCreator.plain("[" + range.text + "]" + "(" + (text ?? "") + ")")], -1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue