Port test from @PatrickShaw #432. Allow infinite captureTimeout in UndoManager #431. Closes #432

This commit is contained in:
Kevin Jahns 2022-10-18 16:45:30 +02:00
parent 8fb73edd97
commit 7395229086
2 changed files with 14 additions and 1 deletions

View File

@ -224,7 +224,7 @@ export class UndoManager extends Observable {
})
const now = time.getUnixTime()
let didAdd = false
if (now - this.lastChange < this.captureTimeout && stack.length > 0 && !undoing && !redoing) {
if (this.lastChange > 0 && now - this.lastChange < this.captureTimeout && stack.length > 0 && !undoing && !redoing) {
// append change to last stack op
const lastOp = stack[stack.length - 1]
lastOp.deletions = mergeDeleteSets([lastOp.deletions, transaction.deleteSet])

View File

@ -3,6 +3,19 @@ import { init, compare, applyRandomTests, Doc } from './testHelper.js' // eslint
import * as Y from '../src/index.js'
import * as t from 'lib0/testing'
/**
* @param {t.TestCase} tc
*/
export const testInfiniteCaptureTimeout = tc => {
const { array0 } = init(tc, { users: 3 })
const undoManager = new Y.UndoManager(array0, { captureTimeout: Number.MAX_VALUE })
array0.push([1, 2, 3])
undoManager.stopCapturing()
array0.push([4, 5, 6])
undoManager.undo()
t.compare(array0.toArray(), [1, 2, 3])
}
/**
* @param {t.TestCase} tc
*/