From ccc92605664077b2e754b04c508567b654dc758b Mon Sep 17 00:00:00 2001 From: Ian Elizondo Date: Tue, 20 Feb 2024 00:07:53 -0600 Subject: [PATCH] [Bump RoosterJS] Content-Model: 0.26.1 (#2426) * Workaround for no mouseUp event (#2423) * bump content model to 0.26.1 --- .../lib/corePlugin/SelectionPlugin.ts | 31 +++++++++++++++++-- versions.json | 2 +- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/packages-content-model/roosterjs-content-model-core/lib/corePlugin/SelectionPlugin.ts b/packages-content-model/roosterjs-content-model-core/lib/corePlugin/SelectionPlugin.ts index 87a0efb2370..286ef0b57e6 100644 --- a/packages-content-model/roosterjs-content-model-core/lib/corePlugin/SelectionPlugin.ts +++ b/packages-content-model/roosterjs-content-model-core/lib/corePlugin/SelectionPlugin.ts @@ -17,6 +17,7 @@ class SelectionPlugin implements PluginWithState { private state: SelectionPluginState; private disposer: (() => void) | null = null; private isSafari = false; + private isMac = false; constructor(options: StandaloneEditorOptions) { this.state = { @@ -43,6 +44,7 @@ class SelectionPlugin implements PluginWithState { const document = this.editor.getDocument(); this.isSafari = !!env.isSafari; + this.isMac = !!env.isMac; if (this.isSafari) { document.addEventListener('selectionchange', this.onSelectionChangeSafari); @@ -91,7 +93,9 @@ class SelectionPlugin implements PluginWithState { (image = this.getClickingImage(event.rawEvent)) && image.isContentEditable && event.rawEvent.button != MouseMiddleButton && - event.isClicking + (event.rawEvent.button == + MouseRightButton /* it's not possible to drag using right click */ || + event.isClicking) ) { this.selectImage(this.editor, image); } @@ -101,7 +105,9 @@ class SelectionPlugin implements PluginWithState { selection = this.editor.getDOMSelection(); if ( event.rawEvent.button === MouseRightButton && - (image = this.getClickingImage(event.rawEvent)) && + (image = + this.getClickingImage(event.rawEvent) ?? + this.getContainedTargetImage(event.rawEvent, selection)) && image.isContentEditable ) { this.selectImage(this.editor, image); @@ -168,6 +174,27 @@ class SelectionPlugin implements PluginWithState { : null; } + //MacOS will not create a mouseUp event if contextMenu event is not prevent defaulted. + //Make sure we capture image target even if image is wrapped + private getContainedTargetImage = ( + event: MouseEvent, + previousSelection: DOMSelection | null + ): HTMLImageElement | null => { + if (!this.isMac || !previousSelection || previousSelection.type !== 'image') { + return null; + } + + const target = event.target as Node; + if ( + isNodeOfType(target, 'ELEMENT_NODE') && + isElementOfType(target, 'span') && + target.firstChild === previousSelection.image + ) { + return previousSelection.image; + } + return null; + }; + private onFocus = () => { if (!this.state.skipReselectOnFocus && this.state.selection) { this.editor?.setDOMSelection(this.state.selection); diff --git a/versions.json b/versions.json index 98fc7538df4..8f58f18e317 100644 --- a/versions.json +++ b/versions.json @@ -1,7 +1,7 @@ { "packages": "8.60.0", "packages-ui": "8.55.0", - "packages-content-model": "0.26.0", + "packages-content-model": "0.26.1", "overrides": { "roosterjs-editor-plugins": "8.60.2", "roosterjs-editor-adapter": "0.26.0"