From 1a8c33c77e991e2646a9ab243ebae8e8633a4541 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlia=20Roldi?= Date: Fri, 6 Oct 2023 11:02:41 -0300 Subject: [PATCH] image selection ctrl --- .../lib/corePlugins/ImageSelection.ts | 11 ++++++-- .../test/corePlugins/imageSelectionTest.ts | 27 +++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/packages/roosterjs-editor-core/lib/corePlugins/ImageSelection.ts b/packages/roosterjs-editor-core/lib/corePlugins/ImageSelection.ts index dc3178fa4f2..3b635e1d06f 100644 --- a/packages/roosterjs-editor-core/lib/corePlugins/ImageSelection.ts +++ b/packages/roosterjs-editor-core/lib/corePlugins/ImageSelection.ts @@ -60,9 +60,16 @@ export default class ImageSelection implements EditorPlugin { } break; case PluginEventType.KeyDown: - const key = event.rawEvent.key; + const rawEvent = event.rawEvent; + const key = rawEvent.key; const keyDownSelection = this.editor.getSelectionRangeEx(); - if (keyDownSelection.type === SelectionRangeTypes.ImageSelection) { + if ( + !rawEvent.ctrlKey && + !rawEvent.altKey && + !rawEvent.shiftKey && + !rawEvent.metaKey && + keyDownSelection.type === SelectionRangeTypes.ImageSelection + ) { if (key === Escape) { this.editor.select(keyDownSelection.image, PositionType.Before); this.editor.getSelectionRange()?.collapse(); diff --git a/packages/roosterjs-editor-core/test/corePlugins/imageSelectionTest.ts b/packages/roosterjs-editor-core/test/corePlugins/imageSelectionTest.ts index 074cd601f4f..60331218a62 100644 --- a/packages/roosterjs-editor-core/test/corePlugins/imageSelectionTest.ts +++ b/packages/roosterjs-editor-core/test/corePlugins/imageSelectionTest.ts @@ -110,6 +110,21 @@ describe('ImageSelectionPlugin |', () => { expect(selection.areAllCollapsed).toBe(true); }); + it('should not handle any key in a image in ctrl', () => { + editor.setContent(``); + const target = document.getElementById(imageId); + editorIsFeatureEnabled.and.returnValue(true); + editor.focus(); + editor.select(target); + const range = document.createRange(); + range.selectNode(target!); + imageSelection.onPluginEvent(keyDown(Space, true)); + imageSelection.onPluginEvent(keyUp(Space, true)); + const selection = editor.getSelectionRangeEx(); + expect(selection.type).toBe(SelectionRangeTypes.ImageSelection); + expect(selection.areAllCollapsed).toBe(false); + }); + it('should handle contextMenu', () => { editor.setContent(``); const target = document.getElementById(imageId); @@ -149,24 +164,32 @@ describe('ImageSelectionPlugin |', () => { expect(editor.select).not.toHaveBeenCalled(); }); - const keyDown = (key: string): PluginEvent => { + const keyDown = (key: string, ctrlKey: boolean = false): PluginEvent => { return { eventType: PluginEventType.KeyDown, rawEvent: { key: key, preventDefault: () => {}, stopPropagation: () => {}, + shiftKey: false, + ctrlKey: ctrlKey, + altKey: false, + metaKey: false, }, }; }; - const keyUp = (key: string): PluginEvent => { + const keyUp = (key: string, ctrlKey: boolean = false): PluginEvent => { return { eventType: PluginEventType.KeyUp, rawEvent: { key: key, preventDefault: () => {}, stopPropagation: () => {}, + shiftKey: false, + ctrlKey: ctrlKey, + altKey: false, + metaKey: false, }, }; };