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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -595,17 +595,20 @@ 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 (selection && !isSingleImageInSelection(selection)) {
const range = selection.getRangeAt(0);
this.editor.setDOMSelection({
type: 'range',
range,
isReverted:
selection.focusNode != range.endContainer ||
selection.focusOffset != range.endOffset,
});
}
if (
newSelection?.type == 'image' &&
selection &&
selection.focusNode &&
!isSingleImageInSelection(selection)
) {
const range = selection.getRangeAt(0);
this.editor.setDOMSelection({
type: 'range',
range,
isReverted:
selection.focusNode != range.endContainer ||
selection.focusOffset != range.endOffset,
});
}

// Safari has problem to handle onBlur event. When blur, we cannot get the original selection from editor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2456,6 +2456,9 @@ describe('SelectionPlugin selectionChange on image selected', () => {
addEventListenerSpy = jasmine.createSpy('addEventListener');
getRangeAtSpy = jasmine.createSpy('getRangeAt');
getSelectionSpy = jasmine.createSpy('getSelection').and.returnValue({
focusNode: {
nodeName: 'SPAN',
},
getRangeAt: getRangeAtSpy,
});
getDocumentSpy = jasmine.createSpy('getDocument').and.returnValue({
Expand Down Expand Up @@ -2513,7 +2516,7 @@ describe('SelectionPlugin selectionChange on image selected', () => {
expect(setDOMSelectionSpy).toHaveBeenCalledWith({
type: 'range',
range: { startContainer: {} } as Range,
isReverted: false,
isReverted: true,
});
expect(getDOMSelectionSpy).toHaveBeenCalledTimes(1);
});
Expand Down
Loading