Normalize line endings in TextBuffer.change()

This commit is contained in:
Kevin Sawicki & Nathan Sobo
2013-07-01 20:06:21 -06:00
committed by Kevin Sawicki
parent 72f9af4d00
commit 05a3f35512
4 changed files with 20 additions and 6 deletions

View File

@@ -1245,6 +1245,7 @@ class Editor extends View
)
intactRanges = newIntactRanges
@pendingChanges = []
intactRanges
truncateIntactRanges: (intactRanges, renderFrom, renderTo) ->

View File

@@ -191,7 +191,8 @@ class TextBuffer
#
# Returns a new {Range}, from `[0, 0]` to the end of the buffer.
getRange: ->
new Range([0, 0], [@getLastRow(), @getLastLine().length])
lastRow = @getLastRow()
new Range([0, 0], [lastRow, @lineLengthForRow(lastRow)])
# Given a range, returns the lines of text within it.
#
@@ -653,12 +654,19 @@ class TextBuffer
abort: -> @undoManager.abort()
change: (oldRange, newText, options) ->
change: (oldRange, newText, options={}) ->
oldRange = Range.fromObject(oldRange)
newText = @normalizeLineEndings(oldRange.start.row, newText) if options.normalizeLineEndings ? true
operation = new BufferChangeOperation({buffer: this, oldRange, newText, options})
range = @pushOperation(operation)
range
normalizeLineEndings: (startRow, text) ->
if lineEnding = @suggestedLineEndingForRow(startRow)
text.replace(/\r?\n/g, lineEnding)
else
text
destroyMarker: (id) ->
if marker = @validMarkers[id] ? @invalidMarkers[id]
delete @validMarkers[id]