The scrolling workaround in that page is just these two lines of code:
var scrollTop = txtarea.scrollTop;
/* change text and set new selection here */
txtarea.scrollTop = scrollTop;
have anyway - replacing the selected text, setting the new selection, etc.
You don't need to replace your existing code to implement the workaround,
just save and restore scrollTop at the right place.