diff --git a/extensions/emmet/src/test/toggleComment.test.ts b/extensions/emmet/src/test/toggleComment.test.ts index c9fc97ad8b4..b2bac920857 100644 --- a/extensions/emmet/src/test/toggleComment.test.ts +++ b/extensions/emmet/src/test/toggleComment.test.ts @@ -187,7 +187,7 @@ suite('Tests for Toggle Comment action from Emmet (CSS)', () => { const expectedContents = ` .one { /*margin: 10px;*/ - padding: 10px; + /*padding: 10px;*/ } /*.two { height: 42px; @@ -199,6 +199,7 @@ suite('Tests for Toggle Comment action from Emmet (CSS)', () => { return withRandomFileEditor(contents, 'css', (editor, doc) => { editor.selections = [ new Selection(2, 2, 2, 15), // A property completely selected + new Selection(3, 0, 3, 16), // A property completely selected along with whitespace new Selection(5, 1, 8, 1), // A rule completely selected ]; @@ -226,7 +227,7 @@ suite('Tests for Toggle Comment action from Emmet (CSS)', () => { }*/`; return withRandomFileEditor(contents, 'css', (editor, doc) => { editor.selections = [ - new Selection(2, 2, 3, 16), // 2 properties completely under a single selection + new Selection(2, 0, 3, 16), // 2 properties completely under a single selection along with whitespace new Selection(5, 1, 11, 2), // 2 rules completely under a single selection ]; diff --git a/extensions/emmet/src/toggleComment.ts b/extensions/emmet/src/toggleComment.ts index eae4bed8208..d91e67016d7 100644 --- a/extensions/emmet/src/toggleComment.ts +++ b/extensions/emmet/src/toggleComment.ts @@ -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;