Quick answer: Godot 4 TextEdit losing undo history after programmatic text assignment? Setting text property clears the buffer - use insert_text_at_caret to preserve history.
Auto-format on Ctrl+S replaces the entire text. After a save, undo is empty.
Replace via insert
text_edit.select_all()
text_edit.insert_text_at_caret(formatted)Editing actions preserve undo. Direct property set does not.
Or batch as a single undo
text_edit.begin_complex_operation()
... insert_text_at_caret(...) ...
text_edit.end_complex_operation()Multiple edits collapse into one undo step.
Verify with the undo button
Inspector tools often use a hidden undo. After your change, press Ctrl+Z manually - if it reverts to pre-format text, undo is preserved.
“Undo history is a property of the editing API. Property sets aren't editing.”
For text editor tools (script editors, dialog editors), establish a rule: never assign text directly. The rule prevents an entire class of UX bug.