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:
Nathan Sobo
2012-10-29 16:04:09 -06:00
parent 88e246b622
commit db3d788664
5 changed files with 28 additions and 14 deletions

View File

@@ -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()

View File

@@ -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)

View File

@@ -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()