Fixed uncomment bug

This commit is contained in:
Armando Aguirre 2020-05-26 19:26:28 -07:00
parent 9f03d7bad7
commit 0985afd51a
6 changed files with 31 additions and 7 deletions

View file

@ -2054,7 +2054,7 @@ namespace ts {
let isCommenting = insertComment || false;
const positions = [] as number[] as SortedArray<number>;
let pos = textRange.pos;
let { pos } = textRange;
const isJsx = isInsideJsx !== undefined ? isInsideJsx : isInsideJsxElement(sourceFile, pos);
const openMultiline = isJsx ? "{/*" : "/*";
@ -2170,8 +2170,16 @@ namespace ts {
function uncommentSelection(fileName: string, textRange: TextRange): TextChange[] {
const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
const textChanges: TextChange[] = [];
const { pos } = textRange;
let { end } = textRange;
for (let i = textRange.pos; i <= textRange.end; i++) {
// If cursor is not a selection we need to increase the end position
// to include the start of the comment.
if (pos === end) {
end += isInsideJsxElement(sourceFile, pos) ? 2 : 1;
}
for (let i = pos; i <= end; i++) {
const commentRange = isInComment(sourceFile, i);
if (commentRange) {
switch (commentRange.kind) {

View file

@ -1,4 +1,4 @@
// Close and open multiline comments if the line already contains more.
// Close and open multiline comments if the line already contains more comments.
//@Filename: file.tsx
//// const a = <div>

View file

@ -1,4 +1,4 @@
// If at least one line is uncomment then comment all lines again.
// If at least one line is not commented then comment all lines again.
//// //const a[| = 1;
//// const b = 2

View file

@ -1,4 +1,4 @@
// If at least one line is uncomment then comment all lines again.
// If at least one line is not commented then comment all lines again.
// TODO: Not sure about this one. The default behavior for line comment is to add en extra
// layer of comments (see toggleLineComment4 test). For jsx this doesn't work right as it's actually
// multiline comment. Figure out what to do.

View file

@ -13,6 +13,10 @@
//// let var8/* = 1;
//// let var9 [||]= 2;
//// let var10 */= 3;
////
//// let var11[||]/* = 1;
//// let var12 = 2;
//// let var13 */= 3;
verify.uncommentSelection(
`let var1 = 1;
@ -27,4 +31,8 @@ let var7 = 7;
let var8 = 1;
let var9 = 2;
let var10 = 3;`);
let var10 = 3;
let var11 = 1;
let var12 = 2;
let var13 = 3;`);

View file

@ -11,6 +11,10 @@
//// SomeText
//// {/*</div>|]*/}
//// </div>;
////
//// const c = <MyContainer>
//// [||]{/*<MyFirstComponent />*/}
//// </MyContainer>;
verify.uncommentSelection(
@ -23,4 +27,8 @@ const b = <div>
<div>
SomeText
</div>
</div>;`);
</div>;
const c = <MyContainer>
<MyFirstComponent />
</MyContainer>;`);