diff --git a/spec/language-mode-spec.coffee b/spec/language-mode-spec.coffee index 35f143636..51cb7c36c 100644 --- a/spec/language-mode-spec.coffee +++ b/spec/language-mode-spec.coffee @@ -208,6 +208,20 @@ describe "LanguageMode", -> languageMode.toggleLineCommentsForBufferRows(0, 0) expect(buffer.lineForRow(0)).toBe "// @color: #4D926F;" + describe "xml", -> + beforeEach -> + editor = atom.project.openSync('sample.xml', autoIndent: false) + editor.setText("") + {buffer, languageMode} = editor + + waitsForPromise -> + atom.packages.activatePackage('language-xml') + + describe "when uncommenting lines", -> + it "removes the leading whitespace from the comment end pattern match", -> + languageMode.toggleLineCommentsForBufferRows(0, 0) + expect(buffer.lineForRow(0)).toBe "test" + describe "folding", -> beforeEach -> editor = atom.project.openSync('sample.js', autoIndent: false) diff --git a/src/language-mode.coffee b/src/language-mode.coffee index 0d7880cfe..093995947 100644 --- a/src/language-mode.coffee +++ b/src/language-mode.coffee @@ -39,13 +39,13 @@ class LanguageMode return unless commentStartString buffer = @editor.buffer - commentStartRegexString = _.escapeRegExp(commentStartString).replace(/(\s+)$/, '($1)?') + commentStartRegexString = _.escapeRegExp(commentStartString).replace(/(\s+)$/, '(?:$1)?') commentStartRegex = new OnigRegExp("^(\\s*)(#{commentStartRegexString})") shouldUncomment = commentStartRegex.test(buffer.lineForRow(start)) if commentEndString if shouldUncomment - commentEndRegexString = _.escapeRegExp(commentEndString).replace(/^(\s+)/, '($1)?') + commentEndRegexString = _.escapeRegExp(commentEndString).replace(/^(\s+)/, '(?:$1)?') commentEndRegex = new OnigRegExp("(#{commentEndRegexString})(\\s*)$") startMatch = commentStartRegex.search(buffer.lineForRow(start)) endMatch = commentEndRegex.search(buffer.lineForRow(end))