diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index 9eb71c9d5..943c0fd8e 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -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") diff --git a/src/app/language-mode.coffee b/src/app/language-mode.coffee index 2f519c8f7..24cba1c52 100644 --- a/src/app/language-mode.coffee +++ b/src/app/language-mode.coffee @@ -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))