Don't explode on meta-/ if there isn't a valid comment regex

This commit is contained in:
Nathan Sobo
2012-09-25 13:27:46 -06:00
parent b00d0bacd9
commit b4b34b0489
2 changed files with 9 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
Project = require 'project'
Buffer = require 'buffer'
EditSession = require 'edit-session'
TextMateBundle = require 'text-mate-bundle'
describe "EditSession", ->
[buffer, editSession, lineLengths] = []
@@ -1347,6 +1348,12 @@ describe "EditSession", ->
editSession.toggleLineCommentsInSelection()
expect(editSession.getSelection().isEmpty()).toBeTruthy()
it "does not explode if the current language mode has no comment regex", ->
spyOn(TextMateBundle, 'lineCommentStringForScope').andReturn(null)
editSession.setSelectedBufferRange([[4, 5], [4, 5]])
editSession.toggleLineCommentsInSelection()
expect(buffer.lineForRow(4)).toBe " while(items.length > 0) {"
describe ".undo() and .redo()", ->
it "undoes/redoes the last change", ->
editSession.insertText("foo")

View File

@@ -47,7 +47,8 @@ class LanguageMode
toggleLineCommentsInRange: (range) ->
range = Range.fromObject(range)
scopes = @tokenizedBuffer.scopesForPosition(range.start)
commentString = TextMateBundle.lineCommentStringForScope(scopes[0])
return unless commentString = TextMateBundle.lineCommentStringForScope(scopes[0])
commentRegex = new OnigRegExp("^\s*" + _.escapeRegExp(commentString))
shouldUncomment = commentRegex.test(@editSession.lineForBufferRow(range.start.row))