mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-19 10:41:56 -05:00
feat(42735): add single line comments to selection ranges (#42763)
This commit is contained in:
@@ -13,10 +13,16 @@ namespace ts.SmartSelectionRange {
|
||||
const prevNode: Node | undefined = children[i - 1];
|
||||
const node: Node = children[i];
|
||||
const nextNode: Node | undefined = children[i + 1];
|
||||
|
||||
if (getTokenPosOfNode(node, sourceFile, /*includeJsDoc*/ true) > pos) {
|
||||
break outer;
|
||||
}
|
||||
|
||||
const comment = singleOrUndefined(getTrailingCommentRanges(sourceFile.text, node.end));
|
||||
if (comment && comment.kind === SyntaxKind.SingleLineCommentTrivia) {
|
||||
pushSelectionCommentRange(comment.pos, comment.end);
|
||||
}
|
||||
|
||||
if (positionShouldSnapToNode(sourceFile, pos, node)) {
|
||||
// 1. Blocks are effectively redundant with SyntaxLists.
|
||||
// 2. TemplateSpans, along with the SyntaxLists containing them, are a somewhat unintuitive grouping
|
||||
@@ -89,6 +95,16 @@ namespace ts.SmartSelectionRange {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function pushSelectionCommentRange(start: number, end: number): void {
|
||||
pushSelectionRange(start, end);
|
||||
|
||||
let pos = start;
|
||||
while (sourceFile.text.charCodeAt(pos) === CharacterCodes.slash) {
|
||||
pos++;
|
||||
}
|
||||
pushSelectionRange(pos, end);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user