mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Change line commenting to ignore blanks if any non-blanks
Fixes #2526 This slightly alters the heuristic for deciding whether to uncomment or to comment blocks of code. Previously, it would key off the first line of code and only if that was commented would it check the other lines. Now it checks all lines of code and uncomments the block if all non-blank lines are commented out.
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user