Don't normalize line endings from Buffer.setText

BufferChangeOperation now takes an options hash that
can specify whether line endings should be normalized.

This option is set to false when Buffer.setText is called.
This replaces the previous assignment of lineEndings to []
with a more explicit mechanism.
This commit is contained in:
Kevin Sawicki & Nathan Sobo
2013-01-27 15:58:00 -08:00
parent 98614592af
commit f6fe2bdc97
2 changed files with 8 additions and 6 deletions

View File

@@ -9,7 +9,8 @@ class BufferChangeOperation
newRange: null
newText: null
constructor: ({@buffer, @oldRange, @newText}) ->
constructor: ({@buffer, @oldRange, @newText, @options}) ->
@options ?= {}
do: ->
@oldText = @buffer.getTextInRange(@oldRange)
@@ -52,7 +53,9 @@ class BufferChangeOperation
startRow = oldRange.start.row
endRow = oldRange.end.row
if suggestedLineEnding = @buffer.suggestedLineEndingForRow(startRow)
normalizeLineEndings = @options.normalizeLineEndings ? true
if normalizeLineEndings and suggestedLineEnding = @buffer.suggestedLineEndingForRow(startRow)
lineEndings[index] = suggestedLineEnding for index in [0..lastLineIndex]
@buffer.lines[startRow..endRow] = lines
@buffer.lineEndings[startRow..endRow] = lineEndings

View File

@@ -109,8 +109,7 @@ class Buffer
@cachedMemoryContents ?= @getTextInRange(@getRange())
setText: (text) ->
@lineEndings = []
@change(@getRange(), text)
@change(@getRange(), text, normalizeLineEndings: false)
getRange: ->
new Range([0, 0], [@getLastRow(), @getLastLine().length])
@@ -206,9 +205,9 @@ class Buffer
delete: (range) ->
@change(range, '')
change: (oldRange, newText) ->
change: (oldRange, newText, options) ->
oldRange = Range.fromObject(oldRange)
operation = new BufferChangeOperation({buffer: this, oldRange, newText})
operation = new BufferChangeOperation({buffer: this, oldRange, newText, options})
range = @pushOperation(operation)
range