mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Use TextMate to toggle comments
This commit is contained in:
@@ -68,16 +68,16 @@ describe "LanguageMode", ->
|
||||
describe ".toggleLineCommentsInRange(range)", ->
|
||||
it "comments/uncomments lines in the given range", ->
|
||||
languageMode.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 "// }"
|
||||
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 "// }"
|
||||
|
||||
languageMode.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 "// }"
|
||||
expect(buffer.lineForRow(6)).toBe "// current < pivot ? left.push(current) : right.push(current);"
|
||||
expect(buffer.lineForRow(7)).toBe "// }"
|
||||
|
||||
describe "fold suggestion", ->
|
||||
describe ".doesBufferRowStartFold(bufferRow)", ->
|
||||
@@ -102,16 +102,16 @@ describe "LanguageMode", ->
|
||||
describe ".toggleLineCommentsInRange(range)", ->
|
||||
it "comments/uncomments lines in the given range", ->
|
||||
languageMode.toggleLineCommentsInRange([[4, 5], [7, 8]])
|
||||
expect(buffer.lineForRow(4)).toBe " #pivot = items.shift()"
|
||||
expect(buffer.lineForRow(5)).toBe " #left = []"
|
||||
expect(buffer.lineForRow(6)).toBe " #right = []"
|
||||
expect(buffer.lineForRow(7)).toBe "#"
|
||||
expect(buffer.lineForRow(4)).toBe "# pivot = items.shift()"
|
||||
expect(buffer.lineForRow(5)).toBe "# left = []"
|
||||
expect(buffer.lineForRow(6)).toBe "# right = []"
|
||||
expect(buffer.lineForRow(7)).toBe "# "
|
||||
|
||||
languageMode.toggleLineCommentsInRange([[4, 5], [5, 8]])
|
||||
expect(buffer.lineForRow(4)).toBe " pivot = items.shift()"
|
||||
expect(buffer.lineForRow(5)).toBe " left = []"
|
||||
expect(buffer.lineForRow(6)).toBe " #right = []"
|
||||
expect(buffer.lineForRow(7)).toBe "#"
|
||||
expect(buffer.lineForRow(6)).toBe "# right = []"
|
||||
expect(buffer.lineForRow(7)).toBe "# "
|
||||
|
||||
describe "fold suggestion", ->
|
||||
describe ".doesBufferRowStartFold(bufferRow)", ->
|
||||
|
||||
@@ -2,6 +2,7 @@ AceAdaptor = require 'ace-adaptor'
|
||||
Range = require 'range'
|
||||
TextMateBundle = require 'text-mate-bundle'
|
||||
_ = require 'underscore'
|
||||
require 'underscore-extensions'
|
||||
|
||||
module.exports =
|
||||
class LanguageMode
|
||||
@@ -62,7 +63,20 @@ class LanguageMode
|
||||
|
||||
toggleLineCommentsInRange: (range) ->
|
||||
range = Range.fromObject(range)
|
||||
@aceMode.toggleCommentLines(@tokenizedBuffer.stackForRow(range.start.row), @aceAdaptor, range.start.row, range.end.row)
|
||||
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)
|
||||
|
||||
text = @editSession.getTextInBufferRange(range)
|
||||
isCommented = new RegExp(commentSource).test text
|
||||
|
||||
if isCommented
|
||||
text = text.replace(new RegExp(commentSource, "gm"), "$1")
|
||||
else
|
||||
text = text.replace(/^/gm, commentString)
|
||||
|
||||
@editSession.setTextInBufferRange(range, text)
|
||||
|
||||
doesBufferRowStartFold: (bufferRow) ->
|
||||
return false if @editSession.isBufferRowBlank(bufferRow)
|
||||
|
||||
Reference in New Issue
Block a user