I'm building a Chrome extension that corrects the users' typings. Upon correction, the corrected word is changed in the input field. The code currently works on textareas, and contenteditables, but I'm facing issues with Draft.js, like Facebook's main post field "What's on your mind": the changed part is reverted when the user sets back the focus on the input field.
Running the following snippet in any page with a Draft.js editor will change the text of the first line, and then set back focus. When that happens, Draft reverts the changed content.
document.querySelector('[data-text=true]').innerHTML='replacement';
setTimeout(function(){
document.querySelector('[contenteditable=true]').focus();
},1000);
JsFiddle Example: https://jsfiddle.net/m6z0xn4r/161/
I would like to find a solution where the changed text would stay there after focus is set back on the input field.
I'm looking for a non-intrusive way to make the text stay as edited. I tried triggering events on the textfield, but nothing worked. I sense that using javascript textselection / range manipulation might be a good way, but no luck so far with that either.
Any help is appreciated!