Skip to content

Commit

Permalink
Merge pull request #2194 from microsoft/u/juliaroldi/select-image
Browse files Browse the repository at this point in the history
Ensure image parent node exist, before select it.
  • Loading branch information
juliaroldi authored Nov 9, 2023
2 parents 5c204ed + 1b3e524 commit a3ec70f
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions packages/roosterjs-editor-core/lib/corePlugins/ImageSelection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PluginEventType, PositionType, SelectionRangeTypes } from 'roosterjs-editor-types';
import { Position, safeInstanceOf } from 'roosterjs-editor-dom';
import { safeInstanceOf } from 'roosterjs-editor-dom';
import type { EditorPlugin, IEditor, PluginEvent } from 'roosterjs-editor-types';

const Escape = 'Escape';
Expand Down Expand Up @@ -70,20 +70,16 @@ export default class ImageSelection implements EditorPlugin {
!rawEvent.metaKey &&
keyDownSelection.type === SelectionRangeTypes.ImageSelection
) {
if (key === Escape) {
const imageParent = keyDownSelection.image?.parentNode;
if (key === Escape && imageParent) {
this.editor.select(keyDownSelection.image, PositionType.Before);
this.editor.getSelectionRange()?.collapse();
event.rawEvent.stopPropagation();
} else if (key === Delete) {
this.editor.deleteNode(keyDownSelection.image);
event.rawEvent.preventDefault();
} else {
const position = new Position(
keyDownSelection.image,
PositionType.Before
);

this.editor.select(position);
} else if (imageParent) {
this.editor.select(keyDownSelection.image, PositionType.Before);
}
}
break;
Expand Down

0 comments on commit a3ec70f

Please sign in to comment.