Commit 87bfda02 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Fix crash when a widget is cached with an old Todo object

When editing one or more todo items, some items may not have changed, therefore
having the exact same source text. The EditCommand still deletes the Todo
instance and creates a new one and puts it in the todo list. But the widget
cache only looked at the source text, found a widget from before the edit and
will use it. But the widget still has a reference to the old Todo instance.
When executing an action on it (e.g. mark it as complete), the TodoList doesn't
remember that todo item, which results in a crash.

Fixed by updating the reference to the latest Todo instance when the sources
are equal but the instances are not.
parent 87f54b40
...@@ -173,6 +173,13 @@ class TodoWidget(urwid.WidgetWrap): ...@@ -173,6 +173,13 @@ class TodoWidget(urwid.WidgetWrap):
if source in p_class.cache: if source in p_class.cache:
widget = p_class.cache[source] widget = p_class.cache[source]
if p_todo is not widget.todo:
# same source text but different todo instance (could happen
# after an edit where a new Todo instance is created with the
# same text as before)
# simply fix the reference in the stored widget.
widget.todo = p_todo
if parent_progress_may_have_changed(p_todo): if parent_progress_may_have_changed(p_todo):
widget.update_progress() widget.update_progress()
else: else:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment