"The whole transformation should vanish with a single Cmd+Z. If it takes three, you built it wrong."
One Action, One Undo
When Flint replaces a selection, the replacement should register in the target app as exactly one undoable edit — so a single Cmd+Z puts the original text back, cleanly. The native AX replace already behaves this way: setting the selected-text attribute is one edit. For paste-based insertion into opaque targets, the equivalent is a single Cmd+V. The rule is 'one strike, one undo': whatever the transformation did, the user can take it back in a single step, in their own app's undo, without Flint having to implement undo itself.
Why Not Type Character by Character
There's a tempting alternative — synthesize the result as individual keystrokes, typing it in character by character. Avoid it wherever you can, because it shatters the undo stack: every character (or chunk) can become its own undo entry, so taking back a transformation means mashing Cmd+Z dozens of times and probably not landing cleanly. A single paste or a single AX replace collapses the whole change into one reversible action. Character-by-character insertion is a last resort for targets that genuinely need it, and it comes with an undo cost you accept deliberately, not by accident.
SINGLE PASTE / AX REPLACE CHARACTER-BY-CHARACTER
------------------------- ----------------------
one edit on the undo stack N edits on the undo stack
Cmd+Z restores original Cmd+Z removes one char
clean, predictable fragmented, frustrating
Prefer the single action. Fall to typing only when forced.
The Paste Also Preserves the Clipboard
Paste-based insertion borrows the clipboard to carry the result, which means it inherits the same obligation the read probe had: preserve what was there. Snapshot the full pasteboard, put the result on it, issue one Cmd+V, then restore the user's original clipboard — every item and type, exactly as in Track 3. So a paste insertion is two disciplines at once: one undoable action for the target, and complete clipboard restoration for the user. The result lands, the undo is clean, and the clipboard the user had is handed back untouched.