Compare commits
1 Commits
v13.0.0-26
...
v13.0.0-25
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ceb7328ec0 |
@@ -17,12 +17,11 @@ window.onload = function () {
|
||||
window.yXmlType.bindToDom(document.body)
|
||||
}
|
||||
window.undoManager = new Y.utils.UndoManager(window.yXmlType, {
|
||||
captureTimeout: 0
|
||||
captureTimeout: 1000
|
||||
})
|
||||
|
||||
document.onkeydown = function interceptUndoRedo (e) {
|
||||
if (e.keyCode === 90 && e.metaKey) {
|
||||
console.log('uidtaren')
|
||||
if (e.keyCode === 90 && e.ctrlKey) {
|
||||
if (!e.shiftKey) {
|
||||
console.info('Undo!')
|
||||
window.undoManager.undo()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "yjs",
|
||||
"version": "13.0.0-26",
|
||||
"version": "13.0.0-25",
|
||||
"description": "A framework for real-time p2p shared editing on any data",
|
||||
"main": "./y.node.js",
|
||||
"browser": "./y.js",
|
||||
|
||||
@@ -24,45 +24,10 @@ function isStructInScope (y, struct, scope) {
|
||||
return false
|
||||
}
|
||||
|
||||
function applyReverseOperation (y, scope, reverseBuffer) {
|
||||
let performedUndo = false
|
||||
y.transact(() => {
|
||||
while (!performedUndo && reverseBuffer.length > 0) {
|
||||
let undoOp = reverseBuffer.pop()
|
||||
// make sure that it is possible to iterate {from}-{to}
|
||||
y.os.getItemCleanStart(undoOp.fromState)
|
||||
y.os.getItemCleanEnd(undoOp.toState)
|
||||
y.os.iterate(undoOp.fromState, undoOp.toState, op => {
|
||||
if (!op._deleted && isStructInScope(y, op, scope)) {
|
||||
performedUndo = true
|
||||
op._delete(y)
|
||||
}
|
||||
})
|
||||
for (let op of undoOp.deletedStructs) {
|
||||
if (
|
||||
isStructInScope(y, op, scope) &&
|
||||
op._parent !== y &&
|
||||
!op._parent._deleted &&
|
||||
(
|
||||
op._parent._id.user !== y.userID ||
|
||||
op._parent._id.clock < undoOp.fromState.clock ||
|
||||
op._parent._id.clock > undoOp.fromState.clock
|
||||
)
|
||||
) {
|
||||
performedUndo = true
|
||||
op = op._copy(undoOp.deletedStructs)
|
||||
op._integrate(y)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
return performedUndo
|
||||
}
|
||||
|
||||
export default class UndoManager {
|
||||
constructor (scope, options = {}) {
|
||||
this.options = options
|
||||
options.captureTimeout = options.captureTimeout == null ? 500 : options.captureTimeout
|
||||
options.captureTimeout = options.captureTimeout || 0
|
||||
this._undoBuffer = []
|
||||
this._redoBuffer = []
|
||||
this._scope = scope
|
||||
@@ -71,11 +36,11 @@ export default class UndoManager {
|
||||
const y = scope._y
|
||||
this.y = y
|
||||
y.on('afterTransaction', (y, remote) => {
|
||||
if (!remote && y._transaction.changedParentTypes.has(scope)) {
|
||||
if (!remote && (y._transaction.beforeState.has(y.userID) || y._transaction.deletedStructs.size > 0)) {
|
||||
let reverseOperation = new ReverseOperation(y)
|
||||
if (!this._undoing) {
|
||||
let lastUndoOp = this._undoBuffer.length > 0 ? this._undoBuffer[this._undoBuffer.length - 1] : null
|
||||
if (lastUndoOp !== null && reverseOperation.created - lastUndoOp.created <= options.captureTimeout) {
|
||||
if (lastUndoOp !== null && lastUndoOp.created - reverseOperation.created <= options.captureTimeout) {
|
||||
console.log('appending', lastUndoOp, reverseOperation)
|
||||
lastUndoOp.created = reverseOperation.created
|
||||
lastUndoOp.toState = reverseOperation.toState
|
||||
@@ -95,14 +60,45 @@ export default class UndoManager {
|
||||
undo () {
|
||||
console.log('undoing')
|
||||
this._undoing = true
|
||||
const performedUndo = applyReverseOperation(this.y, this._scope, this._undoBuffer)
|
||||
this._applyReverseOperation(this._undoBuffer)
|
||||
this._undoing = false
|
||||
return performedUndo
|
||||
}
|
||||
redo () {
|
||||
this._redoing = true
|
||||
const performedRedo = applyReverseOperation(this.y, this._scope, this._redoBuffer)
|
||||
this._applyReverseOperation(this._redoBuffer)
|
||||
this._redoing = false
|
||||
return performedRedo
|
||||
}
|
||||
_applyReverseOperation (reverseBuffer) {
|
||||
this.y.transact(() => {
|
||||
let performedUndo = false
|
||||
while (!performedUndo && reverseBuffer.length > 0) {
|
||||
let undoOp = reverseBuffer.pop()
|
||||
// make sure that it is possible to iterate {from}-{to}
|
||||
this.y.os.getItemCleanStart(undoOp.fromState)
|
||||
this.y.os.getItemCleanEnd(undoOp.toState)
|
||||
this.y.os.iterate(undoOp.fromState, undoOp.toState, op => {
|
||||
if (!op._deleted && isStructInScope(this.y, op, this._scope)) {
|
||||
performedUndo = true
|
||||
op._delete(this.y)
|
||||
}
|
||||
})
|
||||
for (let op of undoOp.deletedStructs) {
|
||||
if (
|
||||
isStructInScope(this.y, op, this._scope) &&
|
||||
op._parent !== this.y &&
|
||||
!op._parent._deleted &&
|
||||
(
|
||||
op._parent._id.user !== this.y.userID ||
|
||||
op._parent._id.clock < undoOp.fromState.clock ||
|
||||
op._parent._id.clock > undoOp.fromState.clock
|
||||
)
|
||||
) {
|
||||
performedUndo = true
|
||||
op = op._copy(undoOp.deletedStructs)
|
||||
op._integrate(this.y)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
82
y.node.js
82
y.node.js
@@ -1,7 +1,7 @@
|
||||
|
||||
/**
|
||||
* yjs - A framework for real-time p2p shared editing on any data
|
||||
* @version v13.0.0-26
|
||||
* @version v13.0.0-25
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
@@ -4390,45 +4390,10 @@ function isStructInScope (y, struct, scope) {
|
||||
return false
|
||||
}
|
||||
|
||||
function applyReverseOperation (y, scope, reverseBuffer) {
|
||||
let performedUndo = false;
|
||||
y.transact(() => {
|
||||
while (!performedUndo && reverseBuffer.length > 0) {
|
||||
let undoOp = reverseBuffer.pop();
|
||||
// make sure that it is possible to iterate {from}-{to}
|
||||
y.os.getItemCleanStart(undoOp.fromState);
|
||||
y.os.getItemCleanEnd(undoOp.toState);
|
||||
y.os.iterate(undoOp.fromState, undoOp.toState, op => {
|
||||
if (!op._deleted && isStructInScope(y, op, scope)) {
|
||||
performedUndo = true;
|
||||
op._delete(y);
|
||||
}
|
||||
});
|
||||
for (let op of undoOp.deletedStructs) {
|
||||
if (
|
||||
isStructInScope(y, op, scope) &&
|
||||
op._parent !== y &&
|
||||
!op._parent._deleted &&
|
||||
(
|
||||
op._parent._id.user !== y.userID ||
|
||||
op._parent._id.clock < undoOp.fromState.clock ||
|
||||
op._parent._id.clock > undoOp.fromState.clock
|
||||
)
|
||||
) {
|
||||
performedUndo = true;
|
||||
op = op._copy(undoOp.deletedStructs);
|
||||
op._integrate(y);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return performedUndo
|
||||
}
|
||||
|
||||
class UndoManager {
|
||||
constructor (scope, options = {}) {
|
||||
this.options = options;
|
||||
options.captureTimeout = options.captureTimeout == null ? 500 : options.captureTimeout;
|
||||
options.captureTimeout = options.captureTimeout || 0;
|
||||
this._undoBuffer = [];
|
||||
this._redoBuffer = [];
|
||||
this._scope = scope;
|
||||
@@ -4437,11 +4402,11 @@ class UndoManager {
|
||||
const y = scope._y;
|
||||
this.y = y;
|
||||
y.on('afterTransaction', (y, remote) => {
|
||||
if (!remote && y._transaction.changedParentTypes.has(scope)) {
|
||||
if (!remote && (y._transaction.beforeState.has(y.userID) || y._transaction.deletedStructs.size > 0)) {
|
||||
let reverseOperation = new ReverseOperation(y);
|
||||
if (!this._undoing) {
|
||||
let lastUndoOp = this._undoBuffer.length > 0 ? this._undoBuffer[this._undoBuffer.length - 1] : null;
|
||||
if (lastUndoOp !== null && reverseOperation.created - lastUndoOp.created <= options.captureTimeout) {
|
||||
if (lastUndoOp !== null && lastUndoOp.created - reverseOperation.created <= options.captureTimeout) {
|
||||
console.log('appending', lastUndoOp, reverseOperation);
|
||||
lastUndoOp.created = reverseOperation.created;
|
||||
lastUndoOp.toState = reverseOperation.toState;
|
||||
@@ -4461,15 +4426,46 @@ class UndoManager {
|
||||
undo () {
|
||||
console.log('undoing');
|
||||
this._undoing = true;
|
||||
const performedUndo = applyReverseOperation(this.y, this._scope, this._undoBuffer);
|
||||
this._applyReverseOperation(this._undoBuffer);
|
||||
this._undoing = false;
|
||||
return performedUndo
|
||||
}
|
||||
redo () {
|
||||
this._redoing = true;
|
||||
const performedRedo = applyReverseOperation(this.y, this._scope, this._redoBuffer);
|
||||
this._applyReverseOperation(this._redoBuffer);
|
||||
this._redoing = false;
|
||||
return performedRedo
|
||||
}
|
||||
_applyReverseOperation (reverseBuffer) {
|
||||
this.y.transact(() => {
|
||||
let performedUndo = false;
|
||||
while (!performedUndo && reverseBuffer.length > 0) {
|
||||
let undoOp = reverseBuffer.pop();
|
||||
// make sure that it is possible to iterate {from}-{to}
|
||||
this.y.os.getItemCleanStart(undoOp.fromState);
|
||||
this.y.os.getItemCleanEnd(undoOp.toState);
|
||||
this.y.os.iterate(undoOp.fromState, undoOp.toState, op => {
|
||||
if (!op._deleted && isStructInScope(this.y, op, this._scope)) {
|
||||
performedUndo = true;
|
||||
op._delete(this.y);
|
||||
}
|
||||
});
|
||||
for (let op of undoOp.deletedStructs) {
|
||||
if (
|
||||
isStructInScope(this.y, op, this._scope) &&
|
||||
op._parent !== this.y &&
|
||||
!op._parent._deleted &&
|
||||
(
|
||||
op._parent._id.user !== this.y.userID ||
|
||||
op._parent._id.clock < undoOp.fromState.clock ||
|
||||
op._parent._id.clock > undoOp.fromState.clock
|
||||
)
|
||||
) {
|
||||
performedUndo = true;
|
||||
op = op._copy(undoOp.deletedStructs);
|
||||
op._integrate(this.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user