Skip to content

Commit

Permalink
Merge branch 'master' into xiaozhe/option-tab-key
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanValverdeU authored Jun 25, 2024
2 parents 0b1f187 + 9dc5f50 commit b719ece
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
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

0 comments on commit b719ece

Please sign in to comment.