Skip to content

Commit

Permalink
Merge pull request #2893 from microsoft/u/juliaroldi/image-drag
Browse files Browse the repository at this point in the history
Remove dragging suffix
  • Loading branch information
juliaroldi authored Nov 26, 2024
2 parents f6b5dca + 206e29e commit 480c729
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ export class ImageEditPlugin implements ImageEditor, EditorPlugin {
}
},
},
dragend: {
beforeDispatch: ev => {
if (this.editor) {
const target = ev.target as Node;
if (this.isImageSelection(target) && target.id.includes(DRAG_ID)) {
target.id = target.id.replace(DRAG_ID, '').trim();
}
}
},
},
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { initEditor } from '../TestHelper';
import {
ContentModelDocument,
ContentModelFormatter,
DOMEventRecord,
EditorEnvironment,
FormatContentModelOptions,
IEditor,
Expand Down Expand Up @@ -64,7 +65,6 @@ describe('ImageEditPlugin', () => {
};
let editor: IEditor;
let mockedEnvironment: EditorEnvironment;
let attachDomEventSpy: jasmine.Spy;
let getDOMSelectionSpy: jasmine.Spy;
let formatContentModelSpy: jasmine.Spy;
let focusSpy: jasmine.Spy;
Expand All @@ -76,8 +76,9 @@ describe('ImageEditPlugin', () => {
let setEditorStyleSpy: jasmine.Spy;
let triggerEventSpy: jasmine.Spy;
let getAttributeSpy: jasmine.Spy;
let domEvents: Record<string, DOMEventRecord> = {};

beforeEach(() => {
attachDomEventSpy = jasmine.createSpy('attachDomEvent');
getDOMSelectionSpy = jasmine.createSpy('getDOMSelection');
mockedEnvironment = {
isSafari: false,
Expand Down Expand Up @@ -124,7 +125,9 @@ describe('ImageEditPlugin', () => {
});
editor = {
getEnvironment: () => mockedEnvironment,
attachDomEvent: attachDomEventSpy,
attachDomEvent: (eventMap: Record<string, DOMEventRecord>) => {
domEvents = eventMap;
},
getDOMSelection: getDOMSelectionSpy,
formatContentModel: formatContentModelSpy,
focus: focusSpy,
Expand Down Expand Up @@ -560,6 +563,35 @@ describe('ImageEditPlugin', () => {
plugin.dispose();
});

it('dragImage only', () => {
const plugin = new ImageEditPlugin();
plugin.initialize(editor);
const draggedImage = document.createElement('img');
draggedImage.id = 'image_0';
triggerEventSpy.and.callThrough();
domEvents.dragstart?.beforeDispatch?.({
target: draggedImage,
} as any);
expect(draggedImage.id).toBe('image_0_dragging');
plugin.dispose();
});

it('dragImage at same place', () => {
const plugin = new ImageEditPlugin();
plugin.initialize(editor);
const draggedImage = document.createElement('img');
draggedImage.id = 'image_0';
triggerEventSpy.and.callThrough();
domEvents.dragstart?.beforeDispatch?.({
target: draggedImage,
} as any);
domEvents.dragend?.beforeDispatch?.({
target: draggedImage,
} as any);
expect(draggedImage.id).toBe('image_0');
plugin.dispose();
});

it('flip setEditorStyle', () => {
const model: ContentModelDocument = {
blockGroupType: 'Document',
Expand Down

0 comments on commit 480c729

Please sign in to comment.