CM5 widget before token

I try to display a widget that is bound to a token immediately after it. The text should remain editable and the widget should be “ignored” when typing/moving the cursor. Ignoring seems to be trivial, but keeping the text editable turns out to be tricky with my approach.

So far I successfully added a bookmark to the start position of the token in the change listener. However I’d also need to verify that it’s not re-added, I need to remove it once the token is gone etc.

Is there a simpler way that I am overlooking? Is the approach the way to go?