diff --git a/extensions/emmet/src/test/toggleComment.test.ts b/extensions/emmet/src/test/toggleComment.test.ts index 4793c3ed819..6e6a5c8252e 100644 --- a/extensions/emmet/src/test/toggleComment.test.ts +++ b/extensions/emmet/src/test/toggleComment.test.ts @@ -726,4 +726,29 @@ suite('Tests for Toggle Comment action from Emmet in nested css (SCSS)', () => { }); }); -}); \ No newline at end of file + test('toggle comment doesn\'t fail when start and end nodes differ HTML', () => { + const contents = ` +
+

Hello

+
+ `; + const expectedContents = ` + + `; + return withRandomFileEditor(contents, 'html', (editor, doc) => { + editor.selections = [ + new Selection(1, 2, 2, 9), //
to

inclusive + ]; + + return toggleComment().then(() => { + assert.equal(doc.getText(), expectedContents); + return toggleComment().then(() => { + assert.equal(doc.getText(), contents); + return Promise.resolve(); + }); + }); + }); + }); +}); diff --git a/extensions/emmet/src/util.ts b/extensions/emmet/src/util.ts index 259a30292d8..17cac93bd4f 100644 --- a/extensions/emmet/src/util.ts +++ b/extensions/emmet/src/util.ts @@ -589,11 +589,20 @@ export function getNodesInBetween(node1: Node, node2: Node): Node[] { return siblings; } +function samePositions(pos1: vscode.Position | undefined, pos2: vscode.Position | undefined): boolean { + if (!pos1 && !pos2) { + return true; + } else if (pos1 && pos2 && pos1.isEqual(pos2)) { + return true; + } + return false; +} + export function sameNodes(node1: Node, node2: Node): boolean { if (!node1 || !node2) { return false; } - return (node1.start).isEqual(node2.start) && (node1.end).isEqual(node2.end); + return samePositions(node1.start, node2.start) && samePositions(node1.end, node2.end); } export function getEmmetConfiguration(syntax: string) {