if the text is sure :f, range.deleteContents() suppose to delete :f, but, it's deleting :f. It looks like space before : character is also getting removed.
How to retain the space before :? Alternatively, Is there any other way to remove text which is more reliable?
const selection = window.getSelection();
const range = document.createRange();
range.setStart(selection.focusNode, 5); // start of :
range.setEnd(selection.focusNode, 7);
range.deleteContents(); //deletes ` :f`
It doesn't matter if I set range.setStart(selection.focusNode, 4) or range.setStart(selection.focusNode, 5).. space is getting removed.
Here's the fiddle to play around: https://jsfiddle.net/JerryGoyal/o2c9f5gw/