Undo & redo model

Ctrl+Z can mean “browser undo” or “editor command”—mixing them with a Rust model requires an explicit policy.

Overview

See also Editor → History management for product-neutral patterns. Here we stress who owns undo when part of the stack is WASM and part is contenteditable.

Browser undo stack

The browser maintains its own undo history for editable regions. Programmatic DOM updates, execCommand, and some frameworks can clear or split that stack—behavior varies by browser.

Model-level history

Robust editors usually implement inverse operations or snapshots on the document model in Rust, then re-render the DOM. Browser undo may be disabled or synchronized via beforeinput interception where supported.

Two independent undo stacks (browser + app) confuse users—pick one authoritative history for text edits.

WASM transactions

Batch model changes into transactions in Rust; expose “undo” as applying inverse ops or rolling back to a checkpoint. Crossing into JS only for DOM patches reduces mismatches.

IME & composition

Undo during IME composition is especially fragile. Often you defer history commits until composition ends—aligns with IME & composition.