mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
Toggling comments adjusts selection's start and end columns
This commit is contained in:
@@ -1315,7 +1315,7 @@ describe "EditSession", ->
|
||||
expect(buffer.lineForRow(5)).toBe "// current = items.shift();"
|
||||
expect(buffer.lineForRow(6)).toBe "// current < pivot ? left.push(current) : right.push(current);"
|
||||
expect(buffer.lineForRow(7)).toBe "// }"
|
||||
expect(editSession.getSelectedBufferRange()).toEqual [[4, 5], [7, 5]]
|
||||
expect(editSession.getSelectedBufferRange()).toEqual [[4, 8], [7, 8]]
|
||||
|
||||
editSession.toggleLineCommentsInSelection()
|
||||
expect(buffer.lineForRow(4)).toBe " while(items.length > 0) {"
|
||||
|
||||
@@ -45,23 +45,20 @@ class LanguageMode
|
||||
@invertedPairedCharacters
|
||||
|
||||
toggleLineCommentsInRange: (range) ->
|
||||
selectedBufferRanges = @editSession.getSelectedBufferRanges()
|
||||
range = Range.fromObject(range)
|
||||
range = new Range([range.start.row, 0], [range.end.row, Infinity])
|
||||
scopes = @tokenizedBuffer.scopesForPosition(range.start)
|
||||
commentString = TextMateBundle.lineCommentStringForScope(scopes[0])
|
||||
commentSource = "^(\s*)" + _.escapeRegExp(commentString)
|
||||
commentRegex = new OnigRegExp("^\s*" + _.escapeRegExp(commentString))
|
||||
|
||||
text = @editSession.getTextInBufferRange(range)
|
||||
isCommented = new RegExp(commentSource).test text
|
||||
shouldUncomment = commentRegex.test(@editSession.lineForBufferRow(range.start.row))
|
||||
|
||||
if isCommented
|
||||
text = text.replace(new RegExp(commentSource, "gm"), "$1")
|
||||
else
|
||||
text = text.replace(/^/gm, commentString)
|
||||
|
||||
@editSession.setTextInBufferRange(range, text)
|
||||
@editSession.setSelectedBufferRanges(selectedBufferRanges)
|
||||
for row in [range.start.row..range.end.row]
|
||||
line = @editSession.lineForBufferRow(row)
|
||||
if shouldUncomment
|
||||
match = commentRegex.search(line)
|
||||
@editSession.buffer.change([[row, 0], [row, match[0].length]], "")
|
||||
else
|
||||
@editSession.buffer.insert([row, 0], commentString)
|
||||
|
||||
doesBufferRowStartFold: (bufferRow) ->
|
||||
return false if @editSession.isBufferRowBlank(bufferRow)
|
||||
@@ -85,7 +82,6 @@ class LanguageMode
|
||||
|
||||
[bufferRow, foldEndRow]
|
||||
|
||||
|
||||
autoIndentBufferRows: (startRow, endRow) ->
|
||||
@autoIndentBufferRow(row) for row in [startRow..endRow]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user