[editor] Fix Undo handling of Markdown text added programmatically
When we insert text into a <textarea> programmatically, such as when adding markdown via a toolbar button (bolding, etc) or auto-continuing a list, we have been simply updating the value of the textarea. This bypasses the natural undo handling of the browser, making it impossible for the user to properly undo the added text.
The execCommand is officially deprecated. However, for insertText, there is currently no alternative. We need to use it in order to trigger the browser's undo tracking when we insert text.
Per https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand on 2022-04-11,
The Clipboard API can be used instead of execCommand in many cases, but execCommand is still sometimes useful. In particular, the Clipboard API doesn't replace the insertText command
So we attempt to use it if possible. Otherwise, fall back to just replacing the value as before. In this case, Undo will be broken with inserted text.
Testing on older versions of Firefox:
-
87and below: does not work and falls through to just replacing value.87was released in Mar 2021 -
89and above: works well.89was released in May 2021
| before | after |
|---|---|
![]() |
![]() |
Related to #250634 (closed)

