44 *--------------------------------------------------------------------------------------------*/
55
66import * as vscode from 'vscode' ;
7- import { getNode , isStyleSheet } from './util' ;
7+ import { getNode , isStyleSheet , getNodesInBetween } from './util' ;
88import parse from '@emmetio/html-matcher' ;
99import parseStylesheet from '@emmetio/css-parser' ;
1010import Node from '@emmetio/node' ;
@@ -58,19 +58,29 @@ export function toggleComment() {
5858}
5959
6060function toggleCommentHTML ( document : vscode . TextDocument , selection : vscode . Selection , rootNode : Node ) : [ vscode . Range [ ] , vscode . Position , vscode . Position ] {
61- let offset = document . offsetAt ( selection . start ) ;
62- let nodeToUpdate = getNode ( rootNode , offset ) ;
63- if ( ! nodeToUpdate ) {
61+ const selectionStart = document . offsetAt ( selection . isReversed ? selection . active : selection . anchor ) ;
62+ const selectionEnd = document . offsetAt ( selection . isReversed ? selection . anchor : selection . active ) ;
63+
64+ let startNode = getNode ( rootNode , selectionStart , true ) ;
65+ let endNode = getNode ( rootNode , selectionEnd , true ) ;
66+
67+ if ( ! startNode || ! endNode ) {
6468 return [ [ ] , null , null ] ;
6569 }
6670
67- let rangesToUnComment = getRangesToUnCommentHTML ( nodeToUpdate , document ) ;
68- if ( nodeToUpdate . type === 'comment' ) {
71+ let allNodes : Node [ ] = getNodesInBetween ( startNode , endNode ) ;
72+ let rangesToUnComment : vscode . Range [ ] = [ ] ;
73+
74+ allNodes . forEach ( node => {
75+ rangesToUnComment = rangesToUnComment . concat ( getRangesToUnCommentHTML ( node , document ) ) ;
76+ } ) ;
77+
78+ if ( startNode . type === 'comment' ) {
6979 return [ rangesToUnComment , null , null ] ;
7080 }
7181
72- let positionForCommentStart = document . positionAt ( nodeToUpdate . start ) ;
73- let positionForCommentEnd = document . positionAt ( nodeToUpdate . end ) ;
82+ let positionForCommentStart = document . positionAt ( allNodes [ 0 ] . start ) ;
83+ let positionForCommentEnd = document . positionAt ( allNodes [ allNodes . length - 1 ] . end ) ;
7484 return [ rangesToUnComment , positionForCommentStart , positionForCommentEnd ] ;
7585}
7686
@@ -95,8 +105,8 @@ function getRangesToUnCommentHTML(node: Node, document: vscode.TextDocument): vs
95105
96106function toggleCommentStylesheet ( document : vscode . TextDocument , selection : vscode . Selection , rootNode : Node ) : [ vscode . Range [ ] , vscode . Position , vscode . Position ] {
97107
98- let selectionStart = document . offsetAt ( selection . anchor ) ;
99- let selectionEnd = document . offsetAt ( selection . active ) ;
108+ const selectionStart = document . offsetAt ( selection . isReversed ? selection . active : selection . anchor ) ;
109+ const selectionEnd = document . offsetAt ( selection . isReversed ? selection . anchor : selection . active ) ;
100110
101111 // If current node is commented, then uncomment and return
102112 let rangesToUnComment = getRangesToUnCommentStylesheet ( rootNode , selectionStart , selectionEnd , document , true ) ;
0 commit comments