From b4b34b048962950724af78eb12857da67ccc0b0f Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 25 Sep 2012 13:27:46 -0600 Subject: [PATCH] Don't explode on `meta-/` if there isn't a valid comment regex --- spec/app/edit-session-spec.coffee | 7 +++++++ src/app/language-mode.coffee | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) 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))