Fixed uncomment bug
This commit is contained in:
parent
381dd8427a
commit
fe91f317de
|
@ -2081,9 +2081,9 @@ namespace ts {
|
|||
|
||||
pos = commentRange.end + 1;
|
||||
} else { // If it's not in a comment range, then we need to comment the uncommented portions.
|
||||
isCommenting = true;
|
||||
let newPos = text.substring(pos, textRange.end).search(`(${openMultilineRegex})|(${closeMultilineRegex})`);
|
||||
|
||||
const newPos = text.substring(pos, textRange.end).search(`(${openMultilineRegex})|(${closeMultilineRegex})`);
|
||||
isCommenting = isCommenting || !isTextWhiteSpaceLike(text, pos, newPos === -1 ? textRange.end : pos + newPos);
|
||||
pos = newPos === -1 ? textRange.end + 1 : pos + newPos + closeMultiline.length;
|
||||
}
|
||||
}
|
||||
|
@ -2130,20 +2130,20 @@ namespace ts {
|
|||
}
|
||||
|
||||
// Insert open comment if the last position is not a comment already.
|
||||
const lastPos = positions[positions.length - 1];
|
||||
if (text.substr(lastPos - closeMultiline.length, closeMultiline.length) !== closeMultiline) {
|
||||
if (textChanges.length % 2 !== 0) {
|
||||
textChanges.push({
|
||||
newText: closeMultiline,
|
||||
span: {
|
||||
length: 0,
|
||||
start: lastPos
|
||||
start: positions[positions.length - 1]
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// If is not commenting then remove all comments found.
|
||||
for (let i = 0; i < positions.length; i++) {
|
||||
const offset = text.substr(positions[i] - closeMultiline.length, closeMultiline.length) === closeMultiline ? closeMultiline.length : 0;
|
||||
const from = positions[i] - closeMultiline.length > 0 ? positions[i] - closeMultiline.length : 0;
|
||||
const offset = text.substr(from, closeMultiline.length) === closeMultiline ? closeMultiline.length : 0;
|
||||
textChanges.push({
|
||||
newText: "",
|
||||
span: {
|
||||
|
|
|
@ -877,14 +877,14 @@ namespace ts {
|
|||
// specially by `getSymbolAtLocation`.
|
||||
if (isModifier(node) && (forRename || node.kind !== SyntaxKind.DefaultKeyword) ? contains(parent.modifiers, node) :
|
||||
node.kind === SyntaxKind.ClassKeyword ? isClassDeclaration(parent) || isClassExpression(node) :
|
||||
node.kind === SyntaxKind.FunctionKeyword ? isFunctionDeclaration(parent) || isFunctionExpression(node) :
|
||||
node.kind === SyntaxKind.InterfaceKeyword ? isInterfaceDeclaration(parent) :
|
||||
node.kind === SyntaxKind.EnumKeyword ? isEnumDeclaration(parent) :
|
||||
node.kind === SyntaxKind.TypeKeyword ? isTypeAliasDeclaration(parent) :
|
||||
node.kind === SyntaxKind.NamespaceKeyword || node.kind === SyntaxKind.ModuleKeyword ? isModuleDeclaration(parent) :
|
||||
node.kind === SyntaxKind.ImportKeyword ? isImportEqualsDeclaration(parent) :
|
||||
node.kind === SyntaxKind.GetKeyword ? isGetAccessorDeclaration(parent) :
|
||||
node.kind === SyntaxKind.SetKeyword && isSetAccessorDeclaration(parent)) {
|
||||
node.kind === SyntaxKind.FunctionKeyword ? isFunctionDeclaration(parent) || isFunctionExpression(node) :
|
||||
node.kind === SyntaxKind.InterfaceKeyword ? isInterfaceDeclaration(parent) :
|
||||
node.kind === SyntaxKind.EnumKeyword ? isEnumDeclaration(parent) :
|
||||
node.kind === SyntaxKind.TypeKeyword ? isTypeAliasDeclaration(parent) :
|
||||
node.kind === SyntaxKind.NamespaceKeyword || node.kind === SyntaxKind.ModuleKeyword ? isModuleDeclaration(parent) :
|
||||
node.kind === SyntaxKind.ImportKeyword ? isImportEqualsDeclaration(parent) :
|
||||
node.kind === SyntaxKind.GetKeyword ? isGetAccessorDeclaration(parent) :
|
||||
node.kind === SyntaxKind.SetKeyword && isSetAccessorDeclaration(parent)) {
|
||||
const location = getAdjustedLocationForDeclaration(parent, forRename);
|
||||
if (location) {
|
||||
return location;
|
||||
|
@ -1947,6 +1947,16 @@ namespace ts {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
export function isTextWhiteSpaceLike(text: string, startPos: number, endPos: number): boolean {
|
||||
for (let i = startPos; i < endPos; i++) {
|
||||
if (!isWhiteSpaceLike(text.charCodeAt(i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// #endregion
|
||||
|
||||
// Display-part writer helpers
|
||||
|
|
12
tests/cases/fourslash/toggleMultilineComment8.ts
Normal file
12
tests/cases/fourslash/toggleMultilineComment8.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
// If the range only contains comments, uncomment all.
|
||||
|
||||
//// /*let var[|1 = 1;*/
|
||||
//// /*let var2 = 2;*/
|
||||
////
|
||||
//// /*let var3 |]= 3;*/
|
||||
|
||||
verify.toggleMultilineComment(
|
||||
`let var1 = 1;
|
||||
let var2 = 2;
|
||||
|
||||
let var3 = 3;`);
|
Loading…
Reference in a new issue