Skip to content

Commit

Permalink
Merge pull request #2819 from microsoft/u/juliaroldi/patch-fix-plugins
Browse files Browse the repository at this point in the history
Patch fix RoosterJS Plugins package
  • Loading branch information
juliaroldi authored Oct 1, 2024
2 parents b72829f + b5bf2fd commit d2ce6eb
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,15 @@ export class ImageEditPlugin implements ImageEditor, EditorPlugin {

private keyDownHandler(editor: IEditor, event: KeyDownEvent) {
if (this.isEditing) {
if (event.rawEvent.key === 'Escape') {
this.removeImageWrapper();
if (
event.rawEvent.key === 'Escape' ||
event.rawEvent.key === 'Delete' ||
event.rawEvent.key === 'Backspace'
) {
if (event.rawEvent.key === 'Escape') {
this.removeImageWrapper();
}
this.cleanInfo();
} else {
this.applyFormatWithContentModel(
editor,
Expand Down Expand Up @@ -610,7 +617,10 @@ export class ImageEditPlugin implements ImageEditor, EditorPlugin {
);
}

private cleanInfo() {
/**
* Exported for testing purpose only
*/
public cleanInfo() {
this.editor?.setEditorStyle(IMAGE_EDIT_CLASS, null);
this.editor?.setEditorStyle(IMAGE_EDIT_CLASS_CARET, null);
this.selectedImage = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,40 @@ describe('ImageEditPlugin', () => {
plugin.dispose();
});

it('keyDown - DELETE', () => {
const mockedImage = {
getAttribute: getAttributeSpy,
};
const plugin = new ImageEditPlugin();
plugin.initialize(editor);
const cleanInfoSpy = spyOn(plugin, 'cleanInfo');
getDOMSelectionSpy.and.returnValue({
type: 'image',
image: mockedImage,
});
const image = createImage('');
const paragraph = createParagraph();
paragraph.segments.push(image);
plugin.onPluginEvent({
eventType: 'mouseUp',
rawEvent: {
button: 0,
target: mockedImage,
} as any,
});
plugin.onPluginEvent({
eventType: 'keyDown',
rawEvent: {
key: 'Delete',
target: mockedImage,
} as any,
});
expect(cleanInfoSpy).toHaveBeenCalled();
expect(cleanInfoSpy).toHaveBeenCalledTimes(1);
expect(formatContentModelSpy).toHaveBeenCalledTimes(1);
plugin.dispose();
});

it('mouseUp', () => {
const mockedImage = {
getAttribute: getAttributeSpy,
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"main": "9.11.0",
"legacyAdapter": "8.62.1",
"overrides": {
"roosterjs-content-model-core": "9.11.1"
"roosterjs-content-model-core": "9.11.1",
"roosterjs-content-model-plugins": "9.11.1"
}
}

0 comments on commit d2ce6eb

Please sign in to comment.