I’m trying to update the current selection from within the update method of a Plugin using:
view.dispatch(state.tr.setSelection(newSelection)); But the selection is not updated.
If I ensure the dispatch runs later using a timeout, it works.
The problem appears to be that without the timeout the dispatched transaction starts running before the previous transaction has finished.
The greater problem is that with a relatively short timeout e.g. 100ms, the selection is only changed about 50% of the time. There appears to be a race condition.
updateStateInner on the view, it appears that there is some
domObserver logic that attempts to workaround some browser bugs and selections. I believe this logic is reverting selection and in effect undoing the selection change transaction.
Is it OK to dispatch transactions within update on a plugin?
Is there a way to ensure a dispatched transaction runs after the current transaction ends without resorting to
Is there any better workaround for the issue I’ve encountered here?