mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 01:04:49 -05:00
PR comments
This commit is contained in:
@@ -1993,7 +1993,7 @@ namespace ts {
|
||||
let isCommenting = insertComment || false;
|
||||
let leftMostPosition = Number.MAX_VALUE;
|
||||
const lineTextStarts = new Map<number>();
|
||||
const whiteSpaceRegex = new RegExp(/\S/);
|
||||
const firstNonWhitespaceCharacterRegex = new RegExp(/\S/);
|
||||
const isJsx = isInsideJsxElement(sourceFile, lineStarts[firstLine]);
|
||||
const openComment = isJsx ? "{/*" : "//";
|
||||
|
||||
@@ -2002,13 +2002,13 @@ namespace ts {
|
||||
const lineText = sourceFile.text.substring(lineStarts[i], sourceFile.getLineEndOfPosition(lineStarts[i]));
|
||||
|
||||
// Find the start of text and the left-most character. No-op on empty lines.
|
||||
const regExec = whiteSpaceRegex.exec(lineText);
|
||||
const regExec = firstNonWhitespaceCharacterRegex.exec(lineText);
|
||||
if (regExec) {
|
||||
leftMostPosition = Math.min(leftMostPosition, regExec.index);
|
||||
lineTextStarts.set(i.toString(), regExec.index);
|
||||
|
||||
if (lineText.substr(regExec.index, openComment.length) !== openComment) {
|
||||
isCommenting = insertComment !== undefined ? insertComment : true;
|
||||
isCommenting = insertComment === undefined || insertComment;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2164,7 +2164,13 @@ namespace ts {
|
||||
}
|
||||
|
||||
function commentSelection(fileName: string, textRange: TextRange): TextChange[] {
|
||||
return toggleLineComment(fileName, textRange, /*insertComment*/ true);
|
||||
const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
|
||||
const { firstLine, lastLine } = getLinesForRange(sourceFile, textRange);
|
||||
|
||||
// If there is a selection that is on the same line, add multiline.
|
||||
return firstLine === lastLine && textRange.pos !== textRange.end
|
||||
? toggleMultilineComment(fileName, textRange, /*insertComment*/ true)
|
||||
: toggleLineComment(fileName, textRange, /*insertComment*/ true);
|
||||
}
|
||||
|
||||
function uncommentSelection(fileName: string, textRange: TextRange): TextChange[] {
|
||||
|
||||
@@ -486,10 +486,10 @@ namespace ts {
|
||||
|
||||
/* @internal */ getNonBoundSourceFile(fileName: string): SourceFile;
|
||||
|
||||
toggleLineComment(fileName: string, textRanges: TextRange): TextChange[];
|
||||
toggleMultilineComment(fileName: string, textRanges: TextRange): TextChange[];
|
||||
commentSelection(fileName: string, textRanges: TextRange): TextChange[];
|
||||
uncommentSelection(fileName: string, textRanges: TextRange): TextChange[];
|
||||
toggleLineComment(fileName: string, textRange: TextRange): TextChange[];
|
||||
toggleMultilineComment(fileName: string, textRange: TextRange): TextChange[];
|
||||
commentSelection(fileName: string, textRange: TextRange): TextChange[];
|
||||
uncommentSelection(fileName: string, textRange: TextRange): TextChange[];
|
||||
|
||||
dispose(): void;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user