Skip to content

Commit 31e19ab

Browse files
committed
feat: track last_changed_field for time-travel navigation
Add last_changed_field property to ObjectState that tracks the field that most recently changed VALUE (not just dirty status). Key difference from last_dirty_field: - last_dirty_field: tracks dirty status changes (clean->dirty or dirty->clean) - last_changed_field: tracks actual value changes regardless of saved state This is essential for time-travel navigation because: - When undoing and a field goes from dirty->clean, we still want to scroll to it - Shows what changed in the transition, not just current dirty state Stores _last_changed_paths from _recompute_fields() and exposes via property.
1 parent 70c8eb6 commit 31e19ab

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/objectstate/object_state.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2418,8 +2418,24 @@ def _recompute_invalid_fields(self) -> Set[str]:
24182418
# Update provenance for this field
24192419
self._live_provenance[dotted_path] = (source_scope_id, source_type)
24202420

2421+
# Store for navigation - fields that changed value in this computation
2422+
self._last_changed_paths = changed_paths
2423+
if changed_paths:
2424+
self._last_changed_field = sorted(
2425+
changed_paths,
2426+
key=lambda field: (field == "func", -field.count("."), field),
2427+
)[0]
24212428
return changed_paths
24222429

2430+
@property
2431+
def last_changed_field(self) -> Optional[str]:
2432+
"""Field that most recently changed value (not just dirty status).
2433+
2434+
This tracks any value change regardless of saved/unsaved state,
2435+
useful for time-travel navigation to show what changed in a transition.
2436+
"""
2437+
return getattr(self, "_last_changed_field", None)
2438+
24232439
def reset_parameter(self, param_name: str) -> None:
24242440
"""Reset parameter to signature default (None for lazy dataclasses).
24252441

0 commit comments

Comments
 (0)