Skip to content

Commit f37f4f0

Browse files
Add documentation about undo manager (#164)
1 parent c3676f6 commit f37f4f0

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

docs/usage.md

+30
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,33 @@ update: bytes
229229
230230
remote_doc.apply_update(update)
231231
```
232+
233+
## Undo manager
234+
235+
An undo manager allows to undo/redo changes to a set of shared types belonging to a document:
236+
237+
```py
238+
from pycrdt import Doc, Text, UndoManager
239+
240+
doc = Doc()
241+
242+
text = doc.get("text", type=Text)
243+
text += "Hello"
244+
245+
undo_manager = UndoManager(doc=doc)
246+
undo_manager.expand_scope(text)
247+
248+
text += ", World!"
249+
print(str(text))
250+
# prints: "Hello, World!"
251+
252+
undo_manager.undo()
253+
print(str(text))
254+
# prints: "Hello"
255+
256+
undo_manager.redo()
257+
print(str(text))
258+
# prints: "Hello, World!"
259+
```
260+
261+
Undoing a change doesn't remove the change from the document's history, but applies a change that is the opposite of the previous change.

0 commit comments

Comments
 (0)