Merge branch 'develop' into sort-imports
This commit is contained in:
commit
f3867ad0a9
107 changed files with 1722 additions and 1208 deletions
|
@ -32,13 +32,13 @@ export function replaceRangeAndExpandSelection(range: Range, newParts: Part[]):
|
|||
});
|
||||
}
|
||||
|
||||
export function replaceRangeAndMoveCaret(range: Range, newParts: Part[]): void {
|
||||
export function replaceRangeAndMoveCaret(range: Range, newParts: Part[], offset = 0): void {
|
||||
const { model } = range;
|
||||
model.transform(() => {
|
||||
const oldLen = range.length;
|
||||
const addedLen = range.replace(newParts);
|
||||
const firstOffset = range.start.asOffset(model);
|
||||
const lastOffset = firstOffset.add(oldLen + addedLen);
|
||||
const lastOffset = firstOffset.add(oldLen + addedLen + offset);
|
||||
return lastOffset.asPosition(model);
|
||||
});
|
||||
}
|
||||
|
@ -103,6 +103,15 @@ export function formatRangeAsCode(range: Range): void {
|
|||
replaceRangeAndExpandSelection(range, parts);
|
||||
}
|
||||
|
||||
export function formatRangeAsLink(range: Range) {
|
||||
const { model, parts } = range;
|
||||
const { partCreator } = model;
|
||||
parts.unshift(partCreator.plain("["));
|
||||
parts.push(partCreator.plain("]()"));
|
||||
// We set offset to -1 here so that the caret lands between the brackets
|
||||
replaceRangeAndMoveCaret(range, parts, -1);
|
||||
}
|
||||
|
||||
// parts helper methods
|
||||
const isBlank = part => !part.text || !/\S/.test(part.text);
|
||||
const isNL = part => part.type === Type.Newline;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue