-
Notifications
You must be signed in to change notification settings - Fork 48
Description
Our BS-tea-based editor uses contenteditable so that we can have a cursor in our app. Unfortunately, we are having difficult interactions between the bs-tea model and placing the cursor which causes significant flicker, and I'm wondering if you've any advice on dealing with this.
If we type quickly, we see this:
What's happening here is that we type "l", "e", "t". We receive events and update our model on each character, which changes the view code. TEA diffs and updates the text node, which as a side-effect causes the browser to reset the cursor to the start of the text node. That's why the cursor is at the start in the gif.
We've been experimenting with different ways of making sure the cursor stays in the same place, but can't get anything right. The code shown in the gif sets the cursor to the right place in a callback (https://gist.github.com/pbiggar/ce30d8028bab49379fb51c2fe11abbca), but the timing is sometimes off and the result in the gif happens.
As an experiment, we tried to do it right after the render loop in Tea_app.ml, and also deep in Vdom.ml (right after Web.Node.set_nodeValue child newText). We found that while we could make it much better, it was extremely brittle and susceptible to minor changes in performance:
Even things like inserting a console.log made a huge difference to render speed.
Our eventual plan was to implement the Custom node type, but given our prototypes aren't doing well, we're not sure where to go with this. Any thoughts?

