mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user