This repository was archived by the owner on Aug 1, 2025. It is now read-only.
fix(onebox): Do not focus editor when inserting/updating search results context#6385
Merged
vovakulikov merged 1 commit intomainfrom Dec 18, 2024
Conversation
…ts context 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 from `editor.update`. Since I've added a helper for creating a promise-version of `editor.update` anyway, I also addressed one of the issues I've encountered in the last PR, namely that `onUpdate` is not called when the editor state doesn't change. This will btw also be fixed on the Lexical side by the above mentioned PR.
0xnmn
approved these changes
Dec 18, 2024
vovakulikov
pushed a commit
that referenced
this pull request
Dec 18, 2024
…ts context (#6385) 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 from `editor.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 that `onUpdate` 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 https://github.com/user-attachments/assets/296cca9e-b8e3-433e-a39a-befbb8fe2017
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
nullwhen making a change.In order to do this I refactored some of the function to make them more composable. Instead of calling
editor.updatedirectly these functions are now supposed to be called fromeditor.update.Since I've added a helper for promisifying
editor.updateanyway, I also addressed one of the issues I've encountered in the last PR, namely thatonUpdateis 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