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

Update superstring #221

Merged
merged 4 commits into from
Mar 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"yargs": "^6.5.0"
},
"dependencies": {
"superstring": "1.1.0",
"superstring": "1.2.1",
"delegato": "^1.0.0",
"diff": "^2.2.1",
"emissary": "^1.0.0",
Expand Down
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
4 changes: 2 additions & 2 deletions src/marker-layer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ class MarkerLayer
destroyMarker: (marker) ->
if @markersById.hasOwnProperty(marker.id)
delete @markersById[marker.id]
@index.delete(marker.id)
@index.remove(marker.id)
@markersWithChangeListeners.delete(marker)
@markersWithDestroyListeners.delete(marker)
@displayMarkerLayers.forEach (displayMarkerLayer) -> displayMarkerLayer.destroyMarker(marker.id)
Expand All @@ -363,7 +363,7 @@ class MarkerLayer
{start, end} = Range.fromObject(range)
start = @delegate.clipPosition(start)
end = @delegate.clipPosition(end)
@index.delete(id)
@index.remove(id)
@index.insert(id, start, end)

setMarkerIsExclusive: (id, exclusive) ->
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