fix(onebox): Do not focus editor when inserting/updating search results context #6385
+206
−137
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.
Closes srch-1483
Changing the focus behavior was more difficult than expected. Apparently when Lexical has a Selection then it will 'steal' the focus whenever changes to its content is made.
There have been made changes to Lexical just recently that would allow us to avoid this (facebook/lexical#6894) but we haven't updated to this version yet and updating this closely before the EAP seems risky.
I found a workaround in one of the discussions that suggests to set the selection to
null
when making a change.In order to do this I refactored some of the function to make them more composable. Instead of calling
editor.update
directly these functions are now supposed to be called fromeditor.update
.Since I've added a helper for promisifying
editor.update
anyway, I also addressed one of the issues I've encountered in the last PR, namely thatonUpdate
is not called when the editor state doesn't change. To prevent accidentally calling it in a way that would not resolve the promise, the callback has to return a boolean.This will btw also be fixed on the Lexical side by the above mentioned PR.
Test plan
Manual testing
sg-ob-follow-up-focus.mp4