2
2
# Distributed under the terms of the Modified BSD License.
3
3
4
4
from abc import ABC , abstractmethod
5
- from typing import Any , Callable , Dict , Optional
5
+ from typing import Any , Callable , Optional
6
6
7
- from pycrdt import Doc , Map , Subscription
7
+ from pycrdt import Doc , Map , Subscription , UndoManager
8
8
9
9
10
10
class YBaseDoc (ABC ):
@@ -15,6 +15,11 @@ class YBaseDoc(ABC):
15
15
subscribe to changes in the document.
16
16
"""
17
17
18
+ _ydoc : Doc
19
+ _ystate : Map
20
+ _subscriptions : dict [Any , Subscription ]
21
+ _undo_manager : UndoManager
22
+
18
23
def __init__ (self , ydoc : Optional [Doc ] = None ):
19
24
"""
20
25
Constructs a YBaseDoc.
@@ -27,7 +32,8 @@ def __init__(self, ydoc: Optional[Doc] = None):
27
32
else :
28
33
self ._ydoc = ydoc
29
34
self ._ystate = self ._ydoc .get ("state" , type = Map )
30
- self ._subscriptions : Dict [Any , Subscription ] = {}
35
+ self ._subscriptions = {}
36
+ self ._undo_manager = UndoManager (doc = self ._ydoc , capture_timeout_millis = 0 )
31
37
32
38
@property
33
39
@abstractmethod
@@ -40,6 +46,15 @@ def version(self) -> str:
40
46
"""
41
47
42
48
@property
49
+ def undo_manager (self ) -> UndoManager :
50
+ """
51
+ A :class:`pycrdt.UndoManager` for the document.
52
+
53
+ :return: The document's undo manager.
54
+ :rtype: :class:`pycrdt.UndoManager`
55
+ """
56
+ return self ._undo_manager
57
+
43
58
def ystate (self ) -> Map :
44
59
"""
45
60
A :class:`pycrdt.Map` containing the state of the document.
0 commit comments