Skip to content

Commit cf7d2bd

Browse files
committed
Add optional file ID to document state
1 parent d9762a1 commit cf7d2bd

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

jupyter_ydoc/ybasedoc.py

+21
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ def path(self) -> Optional[str]:
110110
"""
111111
return self._ystate.get("path")
112112

113+
@property
114+
def file_id(self) -> Optional[str]:
115+
"""
116+
Returns document's file ID.
117+
118+
:return: Document's file ID.
119+
:rtype: Optional[str]
120+
"""
121+
return self._ystate.get("file_id")
122+
113123
@path.setter
114124
def path(self, value: str) -> None:
115125
"""
@@ -121,6 +131,17 @@ def path(self, value: str) -> None:
121131
with self._ydoc.begin_transaction() as t:
122132
self._ystate.set(t, "path", value)
123133

134+
@file_id.setter
135+
def file_id(self, value: str) -> None:
136+
"""
137+
Sets document's file ID.
138+
139+
:param value: Document's file ID.
140+
:type value: str
141+
"""
142+
with self._ydoc.begin_transaction() as t:
143+
self._ystate.set(t, "file_id", value)
144+
124145
@abstractmethod
125146
def get(self) -> Any:
126147
"""

jupyter_ydoc/ynotebook.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def set(self, value: Dict) -> None:
254254
self._ymeta.pop(t, key)
255255
if cells_len:
256256
self._ycells.delete_range(t, 0, cells_len)
257-
for key in [k for k in self._ystate if k not in ("dirty", "path")]:
257+
for key in [k for k in self._ystate if k not in ("dirty", "path", "file_id")]:
258258
self._ystate.pop(t, key)
259259

260260
# initialize document

0 commit comments

Comments
 (0)