Skip to content

Commit

Permalink
Add undo manager timestamp callback test (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart authored Jan 9, 2025
1 parent 7ead3e2 commit c5c4009
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/test_undo.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,27 @@ class Origin:
undo_manager.undo()
assert str(text) == "Hello"
assert not undo_manager.can_undo()


def test_timestamp():
timestamp = 0
timestamp_called = 0

def timestamp_callback():
nonlocal timestamp, timestamp_called
timestamp_called += 1
return timestamp

doc = Doc()
doc["text"] = text = Text()
undo_manager = UndoManager(
scopes=[text], capture_timeout_millis=1, timestamp=timestamp_callback
)
text += "a"
timestamp += 1
text += "b"
text += "c"
timestamp += 1
undo_manager.undo()
assert str(text) == "a"
assert timestamp_called == 4

0 comments on commit c5c4009

Please # to comment.