Readme correction: UndoManager accepts options

This commit is contained in:
Kevin Jahns 2020-04-17 02:02:09 +02:00
parent 9455373611
commit 180f4667c1

View File

@ -650,8 +650,8 @@ ytext.toString() // => 'abc'
``` ```
<dl> <dl>
<b><code>constructor(scope:Y.AbstractType|Array&lt;Y.AbstractType&gt;, <b><code>constructor(scope:Y.AbstractType|Array&lt;Y.AbstractType&gt;
[[{captureTimeout:number,trackedOrigins:Set&lt;any&gt;,deleteFilter:function(item):boolean}]])</code></b> [, {captureTimeout:number,trackedOrigins:Set&lt;any&gt;,deleteFilter:function(item):boolean}])</code></b>
<dd>Accepts either single type as scope or an array of types.</dd> <dd>Accepts either single type as scope or an array of types.</dd>
<b><code>undo()</code></b> <b><code>undo()</code></b>
<dd></dd> <dd></dd>
@ -691,28 +691,28 @@ StackItem won't be merged.
// without stopCapturing // without stopCapturing
ytext.insert(0, 'a') ytext.insert(0, 'a')
ytext.insert(1, 'b') ytext.insert(1, 'b')
um.undo() undoManager.undo()
ytext.toString() // => '' (note that 'ab' was removed) ytext.toString() // => '' (note that 'ab' was removed)
// with stopCapturing // with stopCapturing
ytext.insert(0, 'a') ytext.insert(0, 'a')
um.stopCapturing() undoManager.stopCapturing()
ytext.insert(0, 'b') ytext.insert(0, 'b')
um.undo() undoManager.undo()
ytext.toString() // => 'a' (note that only 'b' was removed) ytext.toString() // => 'a' (note that only 'b' was removed)
``` ```
#### Example: Specify tracked origins #### Example: Specify tracked origins
Every change on the shared document has an origin. If no origin was specified, Every change on the shared document has an origin. If no origin was specified,
it defaults to `null`. By specifying `trackedTransactionOrigins` you can it defaults to `null`. By specifying `trackedOrigins` you can
selectively specify which changes should be tracked by `UndoManager`. The selectively specify which changes should be tracked by `UndoManager`. The
UndoManager instance is always added to `trackedTransactionOrigins`. UndoManager instance is always added to `trackedOrigins`.
```js ```js
class CustomBinding {} class CustomBinding {}
const ytext = doc.getArray('array') const ytext = doc.getArray('array')
const undoManager = new Y.UndoManager(ytext, new Set([42, CustomBinding])) const undoManager = new Y.UndoManager(ytext, { trackedOrigins: new Set([42, CustomBinding]) })
ytext.insert(0, 'abc') ytext.insert(0, 'abc')
undoManager.undo() undoManager.undo()
@ -750,7 +750,7 @@ document. You can assign meta-information to Undo-/Redo-StackItems.
```js ```js
const ytext = doc.getArray('array') const ytext = doc.getArray('array')
const undoManager = new Y.UndoManager(ytext, new Set([42, CustomBinding])) const undoManager = new Y.UndoManager(ytext, { trackedOrigins: new Set([42, CustomBinding]) })
undoManager.on('stack-item-added', event => { undoManager.on('stack-item-added', event => {
// save the current cursor location on the stack-item // save the current cursor location on the stack-item