[Undo] add UndoManager.currStackItem
This commit is contained in:
@@ -52,11 +52,6 @@ const clearUndoManagerStackItem = (tr, um, stackItem) => {
|
||||
* @return {StackItem?}
|
||||
*/
|
||||
const popStackItem = (undoManager, stack, eventType) => {
|
||||
/**
|
||||
* Whether a change happened
|
||||
* @type {StackItem?}
|
||||
*/
|
||||
let result = null
|
||||
/**
|
||||
* Keep a reference to the transaction so we can fire the event with the changedParentTypes
|
||||
* @type {any}
|
||||
@@ -65,7 +60,7 @@ const popStackItem = (undoManager, stack, eventType) => {
|
||||
const doc = undoManager.doc
|
||||
const scope = undoManager.scope
|
||||
transact(doc, transaction => {
|
||||
while (stack.length > 0 && result === null) {
|
||||
while (stack.length > 0 && undoManager.currStackItem === null) {
|
||||
const store = doc.store
|
||||
const stackItem = /** @type {StackItem} */ (stack.pop())
|
||||
/**
|
||||
@@ -113,7 +108,7 @@ const popStackItem = (undoManager, stack, eventType) => {
|
||||
performedChange = true
|
||||
}
|
||||
}
|
||||
result = performedChange ? stackItem : null
|
||||
undoManager.currStackItem = performedChange ? stackItem : null
|
||||
}
|
||||
transaction.changed.forEach((subProps, type) => {
|
||||
// destroy search marker if necessary
|
||||
@@ -123,11 +118,12 @@ const popStackItem = (undoManager, stack, eventType) => {
|
||||
})
|
||||
_tr = transaction
|
||||
}, undoManager)
|
||||
if (result != null) {
|
||||
if (undoManager.currStackItem != null) {
|
||||
const changedParentTypes = _tr.changedParentTypes
|
||||
undoManager.emit('stack-item-popped', [{ stackItem: result, type: eventType, changedParentTypes }, undoManager])
|
||||
undoManager.emit('stack-item-popped', [{ stackItem: undoManager.currStackItem, type: eventType, changedParentTypes }, undoManager])
|
||||
undoManager.currStackItem = null
|
||||
}
|
||||
return result
|
||||
return undoManager.currStackItem
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -196,7 +192,7 @@ export class UndoManager extends Observable {
|
||||
*
|
||||
* @type {StackItem|null}
|
||||
*/
|
||||
this.doingStackItem = null
|
||||
this.currStackItem = null
|
||||
this.lastChange = 0
|
||||
this.ignoreRemoteMapChanges = ignoreRemoteMapChanges
|
||||
this.captureTimeout = captureTimeout
|
||||
@@ -337,12 +333,10 @@ export class UndoManager extends Observable {
|
||||
*/
|
||||
undo () {
|
||||
this.undoing = true
|
||||
this.doingStackItem = array.last(this.undoStack) ?? null
|
||||
let res
|
||||
try {
|
||||
res = popStackItem(this, this.undoStack, 'undo')
|
||||
} finally {
|
||||
this.doingStackItem = null
|
||||
this.undoing = false
|
||||
}
|
||||
return res
|
||||
@@ -355,12 +349,10 @@ export class UndoManager extends Observable {
|
||||
*/
|
||||
redo () {
|
||||
this.redoing = true
|
||||
this.doingStackItem = array.last(this.redoStack) ?? null
|
||||
let res
|
||||
try {
|
||||
res = popStackItem(this, this.redoStack, 'redo')
|
||||
} finally {
|
||||
this.doingStackItem = null
|
||||
this.redoing = false
|
||||
}
|
||||
return res
|
||||
|
||||
Reference in New Issue
Block a user