mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Merge pull request #511 from github/no-trim-whitespace
Leave Markdown files alone when trimming whitespace
This commit is contained in:
@@ -587,7 +587,7 @@ class Buffer
|
||||
# startIndex - The starting row {Number}
|
||||
# endIndex - The ending row {Number}
|
||||
#
|
||||
# Returns an {Array} of {RegExp}s, representing the matches
|
||||
# Returns an {Array} of {RegExp}s, representing the matches.
|
||||
matchesInCharacterRange: (regex, startIndex, endIndex) ->
|
||||
text = @getText()
|
||||
matches = []
|
||||
|
||||
@@ -9,7 +9,10 @@ module.exports =
|
||||
buffer = editSession.buffer
|
||||
buffer.on 'will-be-saved', ->
|
||||
buffer.transact ->
|
||||
buffer.scan /[ \t]+$/g, ({replace}) -> replace('')
|
||||
buffer.scan /[ \t]+$/g, ({match, replace}) ->
|
||||
# GFM permits two whitespaces at the end of a line--trim anything else
|
||||
unless editSession.getGrammar().scopeName is "source.gfm" and match[0] is " "
|
||||
replace('')
|
||||
|
||||
if config.get('whitespace.ensureSingleTrailingNewline')
|
||||
if buffer.getLastLine() is ''
|
||||
|
||||
@@ -86,3 +86,30 @@ describe "Whitespace", ->
|
||||
editor.getBuffer().save()
|
||||
expect(editor.getText()).toBe "foo\n"
|
||||
expect(editor.getCursorBufferPosition()).toEqual([0,3])
|
||||
|
||||
describe "GFM whitespace trimming", ->
|
||||
grammar = null
|
||||
|
||||
beforeEach ->
|
||||
spyOn(syntax, "addGrammar").andCallThrough()
|
||||
atom.activatePackage("gfm")
|
||||
expect(syntax.addGrammar).toHaveBeenCalled()
|
||||
grammar = syntax.addGrammar.argsForCall[0][0]
|
||||
|
||||
it "trims GFM text with a single space", ->
|
||||
editor.activeEditSession.setGrammar(grammar)
|
||||
editor.insertText "foo \nline break!"
|
||||
editor.getBuffer().save()
|
||||
expect(editor.getText()).toBe "foo\nline break!\n"
|
||||
|
||||
it "leaves GFM text with double spaces alone", ->
|
||||
editor.activeEditSession.setGrammar(grammar)
|
||||
editor.insertText "foo \nline break!"
|
||||
editor.getBuffer().save()
|
||||
expect(editor.getText()).toBe "foo \nline break!\n"
|
||||
|
||||
it "trims GFM text with a more than two spaces", ->
|
||||
editor.activeEditSession.setGrammar(grammar)
|
||||
editor.insertText "foo \nline break!"
|
||||
editor.getBuffer().save()
|
||||
expect(editor.getText()).toBe "foo\nline break!\n"
|
||||
|
||||
Reference in New Issue
Block a user