Skip to content

Commit 889264f

Browse files
committed
ensure that autoformat is triggered by token characters
1 parent bbbec22 commit 889264f

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/services/formatting/formatting.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ module ts.formatting {
120120

121121
function findOutermostParent(position: number, expectedTokenKind: SyntaxKind, sourceFile: SourceFile): Node {
122122
var precedingToken = findPrecedingToken(position, sourceFile);
123-
if (!precedingToken || precedingToken.kind !== expectedTokenKind) {
123+
if (!precedingToken ||
124+
precedingToken.kind !== expectedTokenKind ||
125+
position !== precedingToken.getEnd()) {
124126
return undefined;
125127
}
126128

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// <reference path='fourslash.ts'/>
2+
////class A {
3+
////foo( ); // /*1*/
4+
////}
5+
////function foo() { var x; } // /*2*/
6+
7+
goTo.marker("1");
8+
edit.insert(";");
9+
verify.currentLineContentIs("foo( ); // ;")
10+
11+
goTo.marker("2");
12+
edit.insert("}");
13+
verify.currentLineContentIs("function foo() { var x; } // }");

0 commit comments

Comments
 (0)