Uncomment lines that match non-whitespace prefix of comment regex

This commit is contained in:
Kevin Sawicki
2012-10-04 15:36:49 -07:00
parent 23e7139ed1
commit c30220ae80
2 changed files with 16 additions and 1 deletions

View File

@@ -1360,6 +1360,19 @@ describe "EditSession", ->
editSession.toggleLineCommentsInSelection()
expect(buffer.lineForRow(4)).toBe " while(items.length > 0) {"
it "uncomments when the line lacks the trailing whitespace in the comment regex", ->
editSession.setSelectedBufferRange([[10, 0], [10, 0]])
editSession.toggleLineCommentsInSelection()
expect(buffer.lineForRow(10)).toBe "// "
expect(editSession.getSelectedBufferRange()).toEqual [[10, 3], [10, 3]]
editSession.backspace()
expect(buffer.lineForRow(10)).toBe "//"
editSession.toggleLineCommentsInSelection()
expect(buffer.lineForRow(10)).toBe ""
expect(editSession.getSelectedBufferRange()).toEqual [[10, 0], [10, 0]]
describe ".undo() and .redo()", ->
it "undoes/redoes the last change", ->
editSession.insertText("foo")

View File

@@ -49,7 +49,9 @@ class LanguageMode
scopes = @tokenizedBuffer.scopesForPosition(range.start)
return unless commentString = TextMateBundle.lineCommentStringForScope(scopes[0])
commentRegex = new OnigRegExp("^\s*" + _.escapeRegExp(commentString))
commentRegexString = _.escapeRegExp(commentString)
commentRegexString = commentRegexString.replace(/(\s+)$/, '($1)?')
commentRegex = new OnigRegExp("^\s*#{commentRegexString}")
shouldUncomment = commentRegex.test(@editSession.lineForBufferRow(range.start.row))