Skip to content

add undo-aware dirty tracking for documents#1060

Open
Third-Thing wants to merge 1 commit intolapce:mainfrom
Third-Thing:dirty-state-tracking
Open

add undo-aware dirty tracking for documents#1060
Third-Thing wants to merge 1 commit intolapce:mainfrom
Third-Thing:dirty-state-tracking

Conversation

@Third-Thing
Copy link
Copy Markdown
Contributor

@Third-Thing Third-Thing commented Mar 31, 2026

The original proposal (#1054) resulted in users needing to subscribe to cache_rev for reactivity:

Label::derived(move || {
    let _ = doc.cache_rev().get();
    if doc.is_dirty() { "Unsaved" } else { "Saved" }.to_string()
})

This led to a choice between a dedicated reactive dirty-state API, Document::dirty() -> Memo<bool>, or making is_dirty() reactive.

The main reason for choosing the Memo approach was separation of concerns. is_dirty() remains a plain imperative query, while dirty() is the explicit reactive hook for UI. That removes the need to piggyback on cache_rev(), keeps dirty-state subscriptions decoupled from layout/cache invalidation, and makes application code clearer: views subscribe to doc.dirty().get(), while non-reactive code can still call doc.is_dirty().

Further, a tracked is_dirty() would hide reactive behavior behind what looks like a normal getter and would implicitly subscribe callers to the full buffer signal. A dedicated memo is more explicit and only propagates when the dirty boolean actually changes.

With this change, reactive UI becomes:

Label::derived(move || {
    if doc.dirty().get() { "Unsaved" } else { "Saved" }.to_string()
})

This would be a breaking change for types that implement Document. However, given that the existing Document methods imply a dynamic document (not static) it's assumed that the ability to properly track changes will be welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant