At the moment, when applying a style, the original text is wrapped by the style to produce a new node. This new node is then used to replace the content of the range. The result is that the end of the range is outside the style. We need the range (and hence the cursor location) to be inside the style.