Alternative for document.execCommand("insertText", false, text)

40 Views Asked by At

I am using document.execCommand("insertText", false, /* some text */) in a textarea to replace text while allowing Ctrl+Z undo to work; this is supported in every browser I have tested but I know this is deprecated. What is/Is there a better working alternative for this specific case?

Other StackOverflow answers have given alternatives but mostly focus on contenteditable elements and copy/paste, which is irrelevant here.

I also don't feel very comfortable making my own undo/redo stack as it would increase complexity too much. However, if it's the only feasible solution I'm fine doing it.

0

There are 0 best solutions below