From 0411509b435452b7b163daf68f5028e6a47dfd28 Mon Sep 17 00:00:00 2001 From: bene Date: Sat, 29 Oct 2016 14:04:30 +0200 Subject: [PATCH] Fix toggleLineCommentsInSelection for empty lines --- spec/text-editor-spec.coffee | 7 +++++++ src/language-mode.coffee | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index 7ca01f290..4dc035f07 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -4335,6 +4335,13 @@ describe "TextEditor", -> editor.toggleLineCommentsInSelection() expect(buffer.lineForRow(4)).toBe " while(items.length > 0) {" + it "does nothing for empty lines and null grammar", -> + runs -> + editor.setGrammar(atom.grammars.grammarForScopeName('text.plain.null-grammar')) + editor.setCursorBufferPosition([10, 0]) + editor.toggleLineCommentsInSelection() + expect(editor.buffer.lineForRow(10)).toBe "" + it "uncomments when the line lacks the trailing whitespace in the comment regex", -> editor.setCursorBufferPosition([10, 0]) editor.toggleLineCommentsInSelection() diff --git a/src/language-mode.coffee b/src/language-mode.coffee index bb9f339c4..06990bad5 100644 --- a/src/language-mode.coffee +++ b/src/language-mode.coffee @@ -27,7 +27,7 @@ class LanguageMode toggleLineCommentsForBufferRows: (start, end) -> scope = @editor.scopeDescriptorForBufferPosition([start, 0]) commentStrings = @editor.getCommentStrings(scope) - return unless commentStrings? + return unless commentStrings?.commentStartString {commentStartString, commentEndString} = commentStrings buffer = @editor.buffer