Re-Implementing Document.ExecCommand()
The execCommand method has been marked has obsolete, here is how I re-implemented its styling command.
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. — MDN web docs
Without a clear explanation on why nor when, document.execCommand()
has been marked as obsolete in the MDN web docs. Fun fact, it is not marked as deprecated in all languages, as for example French or Spanish which do not mention anything 😜.
For DeckDeckGo, an open source web editor for slides, we have developed and published a custom WYSIWYG editor which relied on such feature.
Because it may be future proof to proactively replace its usage by a custom implementation, I spent quite some time re-implementing it 😄.
Even though my implementation does not look that bad (I hope), I kind of feel, I had to re-implement the wheel. That’s why I am sharing with you my solution, hoping that some of you might point out some improvements or even better, send us pull requests to make the component rock solid 🙏.