Custom placeholder replacement in reply window

We have an Agent Reply Template that I want to be able to add custom data to, using client.data.get("loggedInUser") and then to substitute a custom placeholder such as {{loggedInUser}}

I can retrieve the data, but how can I make the substitutions into the editor. Currently I am replacing the entire text via client.interface.trigger("click", ...) but that isn’t ideal plus it moves the cursor position which I then cannot reset