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

Commit 2e6f336

Browse files
Antonio ScandurraNathan Sobo
authored andcommitted
🎨
Signed-off-by: Nathan Sobo <nathan@github.com>
1 parent fbc2204 commit 2e6f336

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

src/default-history-provider.coffee

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,9 @@ class DefaultHistoryProvider
263263
for entry in @undoStack by -1
264264
switch entry.constructor
265265
when Checkpoint
266-
undoStack.unshift(getCheckpointSnapshot(entry))
266+
undoStack.unshift(snapshotFromCheckpoint(entry))
267267
when Transaction
268-
undoStack.unshift(getTransactionSnapshot(entry))
268+
undoStack.unshift(snapshotFromTransaction(entry))
269269
undoStackPatches.unshift(entry.patch)
270270

271271
break if undoStack.length is maxEntries
@@ -274,9 +274,9 @@ class DefaultHistoryProvider
274274
for entry in @redoStack by -1
275275
switch entry.constructor
276276
when Checkpoint
277-
redoStack.unshift(getCheckpointSnapshot(entry))
277+
redoStack.unshift(snapshotFromCheckpoint(entry))
278278
when Transaction
279-
redoStack.unshift(getTransactionSnapshot(entry))
279+
redoStack.unshift(snapshotFromTransaction(entry))
280280

281281
break if redoStack.length is maxEntries
282282

@@ -365,7 +365,7 @@ class DefaultHistoryProvider
365365
layers[id] = snapshot
366366
layers
367367

368-
getCheckpointSnapshot = (checkpoint) ->
368+
snapshotFromCheckpoint = (checkpoint) ->
369369
{
370370
type: 'checkpoint',
371371
id: checkpoint.id,
@@ -375,10 +375,21 @@ getCheckpointSnapshot = (checkpoint) ->
375375
checkpointFromSnapshot = ({id, markers}) ->
376376
new Checkpoint(id, markers, false)
377377

378-
getTransactionSnapshot = (transaction) ->
378+
snapshotFromTransaction = (transaction) ->
379+
changes = []
380+
for change in transaction.patch.getChanges() by 1
381+
changes.push({
382+
oldStart: change.oldStart,
383+
oldEnd: change.oldEnd,
384+
newStart: change.newStart,
385+
newEnd: change.newEnd,
386+
oldText: change.oldText,
387+
newText: change.newText
388+
})
389+
379390
{
380391
type: 'transaction',
381-
changes: getPatchSnapshot(transaction.patch),
392+
changes,
382393
markersBefore: transaction.markerSnapshotBefore
383394
markersAfter: transaction.markerSnapshotAfter
384395
}
@@ -392,17 +403,3 @@ transactionFromSnapshot = ({changes, markersBefore, markersAfter}) ->
392403

393404
# TODO: Return raw patch if there's no markersBefore && markersAfter
394405
new Transaction(markersBefore, patch, markersAfter)
395-
396-
getPatchSnapshot = (patch) ->
397-
changes = []
398-
for change in patch.getChanges() by 1
399-
changes.push({
400-
oldStart: change.oldStart,
401-
oldEnd: change.oldEnd,
402-
newStart: change.newStart,
403-
newEnd: change.newEnd,
404-
oldText: change.oldText,
405-
newText: change.newText
406-
})
407-
408-
changes

0 commit comments

Comments
 (0)