Compare commits

..

1 Commits

Author SHA1 Message Date
Kevin Jahns
ceb7328ec0 v13.0.0-25 -- distribution files 2017-11-08 17:31:57 -08:00
7 changed files with 86 additions and 95 deletions

View File

@@ -17,12 +17,11 @@ window.onload = function () {
window.yXmlType.bindToDom(document.body) window.yXmlType.bindToDom(document.body)
} }
window.undoManager = new Y.utils.UndoManager(window.yXmlType, { window.undoManager = new Y.utils.UndoManager(window.yXmlType, {
captureTimeout: 0 captureTimeout: 1000
}) })
document.onkeydown = function interceptUndoRedo (e) { document.onkeydown = function interceptUndoRedo (e) {
if (e.keyCode === 90 && e.metaKey) { if (e.keyCode === 90 && e.ctrlKey) {
console.log('uidtaren')
if (!e.shiftKey) { if (!e.shiftKey) {
console.info('Undo!') console.info('Undo!')
window.undoManager.undo() window.undoManager.undo()

View File

@@ -1,6 +1,6 @@
{ {
"name": "yjs", "name": "yjs",
"version": "13.0.0-26", "version": "13.0.0-25",
"description": "A framework for real-time p2p shared editing on any data", "description": "A framework for real-time p2p shared editing on any data",
"main": "./y.node.js", "main": "./y.node.js",
"browser": "./y.js", "browser": "./y.js",

View File

@@ -24,45 +24,10 @@ function isStructInScope (y, struct, scope) {
return false 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 { export default class UndoManager {
constructor (scope, options = {}) { constructor (scope, options = {}) {
this.options = options this.options = options
options.captureTimeout = options.captureTimeout == null ? 500 : options.captureTimeout options.captureTimeout = options.captureTimeout || 0
this._undoBuffer = [] this._undoBuffer = []
this._redoBuffer = [] this._redoBuffer = []
this._scope = scope this._scope = scope
@@ -71,11 +36,11 @@ export default class UndoManager {
const y = scope._y const y = scope._y
this.y = y this.y = y
y.on('afterTransaction', (y, remote) => { 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) let reverseOperation = new ReverseOperation(y)
if (!this._undoing) { if (!this._undoing) {
let lastUndoOp = this._undoBuffer.length > 0 ? this._undoBuffer[this._undoBuffer.length - 1] : null 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) console.log('appending', lastUndoOp, reverseOperation)
lastUndoOp.created = reverseOperation.created lastUndoOp.created = reverseOperation.created
lastUndoOp.toState = reverseOperation.toState lastUndoOp.toState = reverseOperation.toState
@@ -95,14 +60,45 @@ export default class UndoManager {
undo () { undo () {
console.log('undoing') console.log('undoing')
this._undoing = true this._undoing = true
const performedUndo = applyReverseOperation(this.y, this._scope, this._undoBuffer) this._applyReverseOperation(this._undoBuffer)
this._undoing = false this._undoing = false
return performedUndo
} }
redo () { redo () {
this._redoing = true this._redoing = true
const performedRedo = applyReverseOperation(this.y, this._scope, this._redoBuffer) this._applyReverseOperation(this._redoBuffer)
this._redoing = false 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)
}
}
}
})
} }
} }

8
y.js

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1,7 +1,7 @@
/** /**
* yjs - A framework for real-time p2p shared editing on any data * yjs - A framework for real-time p2p shared editing on any data
* @version v13.0.0-26 * @version v13.0.0-25
* @license MIT * @license MIT
*/ */
@@ -4390,45 +4390,10 @@ function isStructInScope (y, struct, scope) {
return false 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 { class UndoManager {
constructor (scope, options = {}) { constructor (scope, options = {}) {
this.options = options; this.options = options;
options.captureTimeout = options.captureTimeout == null ? 500 : options.captureTimeout; options.captureTimeout = options.captureTimeout || 0;
this._undoBuffer = []; this._undoBuffer = [];
this._redoBuffer = []; this._redoBuffer = [];
this._scope = scope; this._scope = scope;
@@ -4437,11 +4402,11 @@ class UndoManager {
const y = scope._y; const y = scope._y;
this.y = y; this.y = y;
y.on('afterTransaction', (y, remote) => { 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); let reverseOperation = new ReverseOperation(y);
if (!this._undoing) { if (!this._undoing) {
let lastUndoOp = this._undoBuffer.length > 0 ? this._undoBuffer[this._undoBuffer.length - 1] : null; 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); console.log('appending', lastUndoOp, reverseOperation);
lastUndoOp.created = reverseOperation.created; lastUndoOp.created = reverseOperation.created;
lastUndoOp.toState = reverseOperation.toState; lastUndoOp.toState = reverseOperation.toState;
@@ -4461,15 +4426,46 @@ class UndoManager {
undo () { undo () {
console.log('undoing'); console.log('undoing');
this._undoing = true; this._undoing = true;
const performedUndo = applyReverseOperation(this.y, this._scope, this._undoBuffer); this._applyReverseOperation(this._undoBuffer);
this._undoing = false; this._undoing = false;
return performedUndo
} }
redo () { redo () {
this._redoing = true; this._redoing = true;
const performedRedo = applyReverseOperation(this.y, this._scope, this._redoBuffer); this._applyReverseOperation(this._redoBuffer);
this._redoing = false; 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