When we create a selection in the transaction, it seems it's applied too early
Closed this issue · 3 comments
Like the transaction did not finish yet. E.g. when switching the text type the selection gets set to the newly created node, which is not yet in the DOM, so the Surface.setSelection produces a warning and the selection is lost.
See:
You didn't get it right.
Transactions are not dealing with the visual selection at all.
A transaction is a sequence of ops, and has a before and after state, which happens to contain a model selection instance. This object is called DocumentChange.
The UI pieces are reacting on 'document:changed' events which comes with a DocumentChange as payload. A Surface itself, or better, its SurfaceManager, renders the selection after each change.
And there is the source of the problem:
As Surfaces are created before any of those TextProperty UI elements, it is registered to the 'document:changed' queue earlier, and thus, always get called before the component rerenders.
We would need somthing like a 'z-index' for event listeners, so that we have more control about the order of triggered listeners.