Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Avoid using legacy patch hunk fields
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Sobo <nathan@github.com>
  • Loading branch information
maxbrunsfeld authored and Nathan Sobo committed Mar 6, 2017
1 parent 2217578 commit 8a40a6f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/helpers.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Point = require './point'
{traversal} = require './point-helpers'

MULTI_LINE_REGEX_REGEX = /\\s|\\r|\\n|\r|\n|^\[\^|[^\\]\[\^/

Expand Down Expand Up @@ -28,8 +29,8 @@ module.exports =
normalizePatchChanges: (changes) ->
changes.map (change) -> {
start: Point.fromObject(change.newStart)
oldExtent: Point.fromObject(change.oldExtent)
newExtent: Point.fromObject(change.newExtent)
oldExtent: traversal(change.oldEnd, change.oldStart)
newExtent: traversal(change.newEnd, change.newStart)
newText: change.newText
}

Expand Down
14 changes: 12 additions & 2 deletions src/text-buffer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ MarkerLayer = require './marker-layer'
MatchIterator = require './match-iterator'
DisplayLayer = require './display-layer'
{spliceArray, newlineRegex, normalizePatchChanges, regexIsSingleLine} = require './helpers'
{traversal} = require './point-helpers'

class TransactionAbortedError extends Error
constructor: -> super
Expand Down Expand Up @@ -622,7 +623,14 @@ class TextBuffer

oldRange = @clipRange(range)
oldText = @getTextInRange(oldRange)
change = {newStart: oldRange.start, oldExtent: oldRange.getExtent(), oldText, newText, normalizeLineEndings}
change = {
oldStart: oldRange.start,
newStart: oldRange.start,
oldEnd: oldRange.end,
oldText,
newText,
normalizeLineEndings
}
@applyChange(change, undo isnt 'skip')

# Public: Insert text at the given position.
Expand Down Expand Up @@ -651,9 +659,10 @@ class TextBuffer

# Applies a change to the buffer based on its old range and new text.
applyChange: (change, pushToHistory = false) ->
{newStart, oldExtent, oldText, newText, normalizeLineEndings} = change
{newStart, oldStart, oldEnd, oldText, newText, normalizeLineEndings} = change
@cachedText = null

oldExtent = traversal(oldEnd, oldStart)
start = Point.fromObject(newStart)
oldRange = Range(start, start.traverse(oldExtent))
oldRange.freeze()
Expand Down Expand Up @@ -693,6 +702,7 @@ class TextBuffer
newRange.freeze()

if pushToHistory
change.oldExtent ?= oldExtent
change.newExtent ?= newExtent
@history?.pushChange(change)

Expand Down

0 comments on commit 8a40a6f

Please sign in to comment.