mirror of
https://github.com/atom/atom.git
synced 2026-02-07 05:05:02 -05:00
Toggle line comments ignores last row of selection if it ends at col 0
Now that the cursor is hidden at the end of a selection, it's counter-intuitive for the commenting to extend to the next line since there's no visual indicator that the cursor extends to that location.
This commit is contained in:
@@ -286,8 +286,8 @@ class EditSession
|
||||
autoDecreaseIndentForRow: (bufferRow) ->
|
||||
@languageMode.autoDecreaseIndentForBufferRow(bufferRow)
|
||||
|
||||
toggleLineCommentsInRange: (range) ->
|
||||
@languageMode.toggleLineCommentsInRange(range)
|
||||
toggleLineCommentsForBufferRows: (start, end) ->
|
||||
@languageMode.toggleLineCommentsForBufferRows(start, end)
|
||||
|
||||
mutateSelectedText: (fn) ->
|
||||
@transact => fn(selection) for selection in @getSelections()
|
||||
|
||||
@@ -64,18 +64,17 @@ class LanguageMode
|
||||
@invertedPairedCharacters[close] = open
|
||||
@invertedPairedCharacters
|
||||
|
||||
toggleLineCommentsInRange: (range) ->
|
||||
range = Range.fromObject(range)
|
||||
scopes = @getTokenizedBuffer().scopesForPosition(range.start)
|
||||
toggleLineCommentsForBufferRows: (start, end) ->
|
||||
scopes = @getTokenizedBuffer().scopesForPosition([start, 0])
|
||||
return unless commentString = TextMateBundle.lineCommentStringForScope(scopes[0])
|
||||
|
||||
commentRegexString = _.escapeRegExp(commentString)
|
||||
commentRegexString = commentRegexString.replace(/(\s+)$/, '($1)?')
|
||||
commentRegex = new OnigRegExp("^\s*#{commentRegexString}")
|
||||
|
||||
shouldUncomment = commentRegex.test(@editSession.lineForBufferRow(range.start.row))
|
||||
shouldUncomment = commentRegex.test(@editSession.lineForBufferRow(start))
|
||||
|
||||
for row in [range.start.row..range.end.row]
|
||||
for row in [start..end]
|
||||
line = @editSession.lineForBufferRow(row)
|
||||
if shouldUncomment
|
||||
if match = commentRegex.search(line)
|
||||
|
||||
@@ -67,6 +67,13 @@ class Selection
|
||||
else
|
||||
new Range(@cursor.getBufferPosition(), @cursor.getBufferPosition())
|
||||
|
||||
getBufferRowRange: ->
|
||||
range = @getBufferRange()
|
||||
start = range.start.row
|
||||
end = range.end.row
|
||||
end = Math.max(start, end - 1) if range.end.column == 0
|
||||
[start, end]
|
||||
|
||||
screenRangeChanged: ->
|
||||
screenRange = @getScreenRange()
|
||||
@trigger 'change-screen-range', screenRange
|
||||
@@ -272,7 +279,7 @@ class Selection
|
||||
|
||||
toggleLineComments: ->
|
||||
@modifySelection =>
|
||||
@editSession.toggleLineCommentsInRange(@getBufferRange())
|
||||
@editSession.toggleLineCommentsForBufferRows(@getBufferRowRange()...)
|
||||
|
||||
cutToEndOfLine: (maintainPasteboard) ->
|
||||
@selectToEndOfLine() if @isEmpty()
|
||||
|
||||
Reference in New Issue
Block a user