Forcibly call onblur on Inspector inputs before changing selection #240
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.
Fixes #220
Problem:
Changes made to an Inspector input are not applied when clicking elsewhere in the editor
Fix:
(For the TLDR that doesn't require reading my life story, skip to the bit in bold at the bottom.)
I have been to the pits of hell with this one, and whilst this solution may be ugly, let me tell you this - it is the best you're getting without huge amounts of refactoring (even then don't count on it). This has been one of those issues where it seems tiny and easy to fix, so you make a fix and realise that something else is now getting in the way, but over and over and over. To give you an idea:
onClickOutside
that we use...onClickOutside
doesn't fire when clicking the canvas. U WOT M8?! No joke. It's because it works by adding an event listener to thedocument
, but that event listener ends up being later in the queue than all of the others, meaning the selection has changed before it is reached, and it is removed upon destruction of the wrapped component. Ok fine, let's try adding a click catcher over the top of everything for forcibly blurring this shit...So, finally, in a case of "one last go before I throw in the towel", I found an existing case where we were tying a
mousedown
listener to the window, and made that check if the currently focused element was an inspector input (required to prevent it screwing up interaction withreact-select
elements and probably others), and the event was targeting a different element, in which case we forcibly callblur()
.Commit Details:
InspectorInput
so that we could add the attributedata-inspector-input
to itmousedown
event listener attached to the window to check if adata-inspector-input
should be blurred, and if so callblur()
on ittrue
for thecapture
param when adding the above listener to make sure it is handled before other listeners of that event (which should have been happening before, though I'm not sure if that old functionality is actually used anywhere)