diff --git a/src/language-mode.coffee b/src/language-mode.coffee index 83d50a74b..fad18d645 100644 --- a/src/language-mode.coffee +++ b/src/language-mode.coffee @@ -41,9 +41,9 @@ class LanguageMode buffer = @editor.buffer commentStartRegexString = _.escapeRegExp(commentStartString).replace(/(\s+)$/, '(?:$1)?') commentStartRegex = new OnigRegExp("^(\\s*)(#{commentStartRegexString})") - shouldUncomment = commentStartRegex.test(buffer.lineForRow(start)) if commentEndString + shouldUncomment = commentStartRegex.test(buffer.lineForRow(start)) if shouldUncomment commentEndRegexString = _.escapeRegExp(commentEndString).replace(/^(\s+)/, '(?:$1)?') commentEndRegex = new OnigRegExp("(#{commentEndRegexString})(\\s*)$") @@ -64,10 +64,18 @@ class LanguageMode buffer.insert([start, indentLength], commentStartString) buffer.insert([end, buffer.lineLengthForRow(end)], commentEndString) else - if shouldUncomment and start isnt end - shouldUncomment = [start+1..end].every (row) -> - line = buffer.lineForRow(row) - not line or commentStartRegex.test(line) + blankRegex = new OnigRegExp("^\\s*$") + + allBlank = true + allBlankOrCommented = [start..end].every (row) -> + line = buffer.lineForRow(row) + blank = not line or blankRegex.test(line) + + allBlank = allBlank and blank + blank or commentStartRegex.test(line) + + shouldUncomment = allBlankOrCommented and not allBlank + if shouldUncomment for row in [start..end] if match = commentStartRegex.search(buffer.lineForRow(row))