Right, undo doesn’t work by default whenever you use JavaScript to modify an input. But I googled around and found that document.execCommand can insert text while appending to the undo stack.
For example, if you do document.getElementById('myInput').value = 'asd' and then Ctrl+Z, it won’t undo.
But if you do document.execCommand('insertText', false, 'asd') while the cursor is where you want it (which it should be based on the current Discourse workflow), the text is properly inserted and Ctrl+Z will remove the added text as expected.
Basically, I’m wondering if document.execCommand (or some other process if another approach is considered better) can be used to append to the undo stack so Ctrl+Z works in these cases.