Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/services/formatting/formatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,13 @@ namespace ts.formatting {

let listDynamicIndentation = parentDynamicIndentation;
let startLine = parentStartLine;
// node range is outside the target range - do not dive inside
if (!rangeOverlapsWithStartEnd(originalRange, nodes.pos, nodes.end)) {
if (nodes.end < originalRange.pos) {
formattingScanner.skipToEndOf(nodes);
}
return;
}

if (listStartToken !== SyntaxKind.Unknown) {
// introduce a new indentation scope for lists (including list start and end tokens)
Expand Down
4 changes: 2 additions & 2 deletions src/services/formatting/formattingScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace ts.formatting {
readEOFTokenRange(): TextRangeWithKind;
getCurrentLeadingTrivia(): TextRangeWithKind[] | undefined;
lastTrailingTriviaWasNewLine(): boolean;
skipToEndOf(node: Node): void;
skipToEndOf(node: Node | NodeArray<Node>): void;
skipToStartOf(node: Node): void;
}

Expand Down Expand Up @@ -286,7 +286,7 @@ namespace ts.formatting {
return tokenInfo;
}

function skipToEndOf(node: Node): void {
function skipToEndOf(node: Node | NodeArray<Node>): void {
scanner.setTextPos(node.end);
savedPos = scanner.getStartPos();
lastScanAction = undefined;
Expand Down
9 changes: 9 additions & 0 deletions tests/cases/fourslash/formatAfterPasteInString.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// <reference path='fourslash.ts' />

//// /*2*/const x = f('aa/*1*/a').x()

goTo.marker('1');
edit.paste("bb");
format.document();
goTo.marker('2');
verify.currentLineContentIs("const x = f('aabba').x()");