@@ -228,15 +228,24 @@ define(function (require, exports, module) {
228228
229229 // Check if we should just do a line uncomment (if all lines in the selection are commented).
230230 if ( slashComment && ( ctx . token . string . match ( lineExp ) || endCtx . token . string . match ( lineExp ) ) ) {
231+ var ctxPos = { line : ctx . pos . line , ch : ctx . pos . ch } ;
232+ var endCtxIndex = editor . indexFromPos ( { line : endCtx . pos . line , ch : endCtx . token . start + endCtx . token . string . length } ) ;
233+
231234 // Find if we aren't actually inside a block-comment
232235 result = true ;
233236 while ( result && ctx . token . string . match ( lineExp ) ) {
234237 result = TokenUtils . moveSkippingWhitespace ( TokenUtils . movePrevToken , ctx ) ;
235238 }
236239
240+ // If we aren't in a block-comment.
237241 if ( ! result || ctx . token . className !== "comment" || ctx . token . string . match ( suffixExp ) ) {
238- // We aren't in an block-comment. Find if all the lines are line-commented.
239- if ( ! _containsUncommented ( editor , sel . start . line , sel . end . line ) ) {
242+ // If the selection includes all the line-comments, do a block-comment
243+ if ( editor . posWithinRange ( ctxPos , sel . start , sel . end ) &&
244+ ( ! endCtx . token . string . match ( lineExp ) || editor . indexFromPos ( sel . end ) >= endCtxIndex ) ) {
245+ canComment = true ;
246+
247+ // Find if all the lines are line-commented.
248+ } else if ( ! _containsUncommented ( editor , sel . start . line , sel . end . line ) ) {
240249 lineUncomment = true ;
241250
242251 // If can't uncomment then do nothing, since it would create an invalid comment.
0 commit comments