fix: Formatting toolbar opening on drop #944
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When you drag & drop a block, the editor is blurred and its state is updated. However, the blur gets handled async and so the state updates before the editor has actually been blurred. This is a problem for the formatting toolbar, which updates whenever the editor state does but also needs to know if the editor is blurred to decide whether to show. Like the editor state, it also updates before the editor is blurred, and so it shows up on drop. Additionally, the blur doesn't trigger a state update, only a view update, and so doesn't re-trigger an update on the formatting toolbar.
This PR re-adds the blur event listener to the editor, for the formatting toolbar to update whenever the editor loses focus. This is not totally ideal as it gets updated twice on drop, but I think it's cleaner than delaying the update using a
setTimeout
instead which is the alternative approach. Accessibility using the keyboard still works with these changes.Closes #929