From 02d81f533b66a036aba09c123dcb0f78f4397ae9 Mon Sep 17 00:00:00 2001 From: David Brochart Date: Sun, 12 May 2024 18:45:06 +0200 Subject: [PATCH] Fix ignoring empty update (#111) * Add test for non-empty update * Add fix for ignoring empty update --- src/doc.rs | 2 +- tests/test_doc.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/doc.rs b/src/doc.rs index dbf1e41..32284b4 100644 --- a/src/doc.rs +++ b/src/doc.rs @@ -116,7 +116,7 @@ impl Doc { pub fn observe(&mut self, py: Python<'_>, f: PyObject) -> PyResult> { let sub = self.doc .observe_transaction_cleanup(move |txn, event| { - if event.before_state != event.after_state { + if !event.delete_set.is_empty() || event.before_state != event.after_state { Python::with_gil(|py| { let event = TransactionEvent::new(event, txn); if let Err(err) = f.call1(py, (event,)) { diff --git a/tests/test_doc.py b/tests/test_doc.py index e54f3b1..97c2437 100644 --- a/tests/test_doc.py +++ b/tests/test_doc.py @@ -191,3 +191,15 @@ def test_empty_update(): doc["text"] # empty updates should not emit an event assert not events + + +def test_not_empty_update(): + doc = Doc() + doc["text"] = text = Text() + events = [] + sub = doc.observe(partial(callback, events)) # noqa: F841 + + text += "helloo" + events.clear() + del text[5] + assert events