From f6fe2bdc97c9edc2ca947d3b212ca74babb2481d Mon Sep 17 00:00:00 2001 From: Kevin Sawicki & Nathan Sobo Date: Sun, 27 Jan 2013 15:58:00 -0800 Subject: [PATCH] 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. --- src/app/buffer-change-operation.coffee | 7 +++++-- src/app/buffer.coffee | 7 +++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/app/buffer-change-operation.coffee b/src/app/buffer-change-operation.coffee index c50bb2308..2a31ab244 100644 --- a/src/app/buffer-change-operation.coffee +++ b/src/app/buffer-change-operation.coffee @@ -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 diff --git a/src/app/buffer.coffee b/src/app/buffer.coffee index cbff0b2d9..266b30ba2 100644 --- a/src/app/buffer.coffee +++ b/src/app/buffer.coffee @@ -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