mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Normalize line endings in TextBuffer.change()
This commit is contained in:
committed by
Kevin Sawicki
parent
72f9af4d00
commit
05a3f35512
@@ -1245,6 +1245,7 @@ class Editor extends View
|
||||
)
|
||||
intactRanges = newIntactRanges
|
||||
@pendingChanges = []
|
||||
|
||||
intactRanges
|
||||
|
||||
truncateIntactRanges: (intactRanges, renderFrom, renderTo) ->
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user