mirror of
https://github.com/atom/atom.git
synced 2026-01-24 22:38:20 -05:00
LineCommenter.proto.toggleLineCommentsInRange comments / uncomments lines in a selection
This commit is contained in:
@@ -10,9 +10,16 @@ describe "LineCommenter", ->
|
||||
highlighter = new Highlighter(buffer)
|
||||
lineCommenter = new LineCommenter(highlighter)
|
||||
|
||||
fdescribe "toggleLineCommentsInRange", ->
|
||||
lineCommenter.toggleLineCommentsInRange([[4, 5], [7, 8]])
|
||||
expect(buffer.lineForRow(4)).toBe "// while(items.length > 0) {"
|
||||
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 "// }"
|
||||
describe "toggleLineCommentsInRange", ->
|
||||
it "comments/uncomments lines in the given range", ->
|
||||
lineCommenter.toggleLineCommentsInRange([[4, 5], [7, 8]])
|
||||
expect(buffer.lineForRow(4)).toBe "// while(items.length > 0) {"
|
||||
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 "// }"
|
||||
|
||||
lineCommenter.toggleLineCommentsInRange([[4, 5], [5, 8]])
|
||||
expect(buffer.lineForRow(4)).toBe " while(items.length > 0) {"
|
||||
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 "// }"
|
||||
|
||||
16
src/app/ace-line-comment-adaptor.coffee
Normal file
16
src/app/ace-line-comment-adaptor.coffee
Normal file
@@ -0,0 +1,16 @@
|
||||
Range = require 'range'
|
||||
|
||||
module.exports =
|
||||
class AceLineCommentAdaptor
|
||||
constructor: (@buffer) ->
|
||||
|
||||
getLine: (row) ->
|
||||
@buffer.lineForRow(row)
|
||||
|
||||
indentRows: (startRow, endRow, indentString) ->
|
||||
for row in [startRow..endRow]
|
||||
@buffer.insert([row, 0], indentString)
|
||||
|
||||
replace: (range, text) ->
|
||||
range = Range.fromObject(range)
|
||||
@buffer.change(range, text)
|
||||
@@ -1,4 +1,5 @@
|
||||
Range = require 'range'
|
||||
AceLineCommentAdaptor = require 'ace-line-comment-adaptor'
|
||||
|
||||
module.exports =
|
||||
class LineCommenter
|
||||
@@ -9,9 +10,8 @@ class LineCommenter
|
||||
constructor: (@highlighter) ->
|
||||
@buffer = @highlighter.buffer
|
||||
@aceMode = @buffer.getMode()
|
||||
@adaptor = new AceLineCommentAdaptor(@buffer)
|
||||
|
||||
toggleLineCommentsInRange: (range) ->
|
||||
range = Range.fromObject(range)
|
||||
|
||||
@aceMode.tog
|
||||
|
||||
@aceMode.toggleCommentLines(@highlighter.stateForRow(range.start.row), @adaptor, range.start.row, range.end.row)
|
||||
|
||||
@@ -6,9 +6,10 @@ class Range
|
||||
@fromObject: (object) ->
|
||||
if _.isArray(object)
|
||||
new Range(object...)
|
||||
else
|
||||
else if object instanceof Range
|
||||
object
|
||||
|
||||
else
|
||||
new Range(object.start, object.end)
|
||||
|
||||
constructor: (pointA = new Point(0, 0), pointB = new Point(0, 0)) ->
|
||||
pointA = Point.fromObject(pointA)
|
||||
|
||||
Reference in New Issue
Block a user