Toggle comment shld ignore whitespace when fetching nodes

This commit is contained in:
Ramya Achutha Rao
2017-07-26 19:45:28 -07:00
parent d83273825d
commit cfe354d268
2 changed files with 25 additions and 4 deletions

View File

@@ -106,10 +106,30 @@ function toggleCommentStylesheet(document: vscode.TextDocument, selection: vscod
let startNode = getNode(rootNode, selectionStart, true);
let endNode = getNode(rootNode, selectionEnd, true);
if (sameNodes(startNode, endNode)) {
selection = new vscode.Selection(startNode.start, endNode.end);
if (startNode && endNode) {
if (sameNodes(startNode, endNode) || sameNodes(startNode.parent, endNode.parent)) {
selection = new vscode.Selection(startNode.start, endNode.end);
} else {
if (sameNodes(startNode, endNode.parent)) {
let newStartNode = startNode.firstChild;
while (newStartNode.end.isBefore(selectionStart) && newStartNode.nextSibling) {
newStartNode = newStartNode.nextSibling;
}
startNode = newStartNode;
} else if (sameNodes(startNode.parent, endNode)) {
let newEndNode = endNode.children[endNode.children.length - 1];
while (newEndNode.end.isAfter(selectionEnd) && newEndNode.previousSibling) {
newEndNode = newEndNode.previousSibling;
}
endNode = newEndNode;
}
// TODO: both are properties of different rule : have 2 comments for the 2 rules
}
}
let rangesToUnComment: vscode.Range[] = [];
let isFirstNodeCommented = false;