Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure focusNode exists when selectionChanges #2724

Merged
merged 3 commits into from
Jun 24, 2024

Conversation

juliaroldi
Copy link
Contributor

When selectionChange event happens, ensure the focus exist before setting the selection in the new position, otherwise
getRangeSelection(0) will return an error, since nothing is selected.

@@ -595,7 +595,7 @@ class SelectionPlugin implements PluginWithState<SelectionPluginState> {
//If am image selection changed to a wider range due a keyboard event, we should update the selection
const selection = this.editor.getDocument().getSelection();

if (newSelection?.type == 'image' && selection) {
if (newSelection?.type == 'image' && selection && selection.focusNode) {
if (selection && !isSingleImageInSelection(selection)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we checked "selection" twice, in line 598 and 599. These two lines can be merged

@juliaroldi juliaroldi merged commit 9dc5f50 into master Jun 24, 2024
7 checks passed
@juliaroldi juliaroldi deleted the u/juliaroldi/verify-focus-node branch June 24, 2024 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants