Skip to content

Commit

Permalink
Merge pull request #15998 from ckeditor/ck/15994
Browse files Browse the repository at this point in the history
Fix(image): Loading the `ImageResize` plugin before `ImageBlock` or `ImageInline` should not crash the editor. Closes #15994.
  • Loading branch information
pszczesniak committed Mar 7, 2024
2 parents 0b32907 + 9d8c653 commit de65bbd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Expand Up @@ -72,7 +72,6 @@ export default class ImageResizeEditing extends Plugin {
const editor = this.editor;
const resizeImageCommand = new ResizeImageCommand( editor );

this._registerSchema();
this._registerConverters( 'imageBlock' );
this._registerConverters( 'imageInline' );

Expand All @@ -81,6 +80,13 @@ export default class ImageResizeEditing extends Plugin {
editor.commands.add( 'imageResize', resizeImageCommand );
}

/**
* @inheritDoc
*/
public afterInit(): void {
this._registerSchema();
}

private _registerSchema(): void {
if ( this.editor.plugins.has( 'ImageBlockEditing' ) ) {
this.editor.model.schema.extend( 'imageBlock', { allowAttributes: [ 'resizedWidth', 'resizedHeight' ] } );
Expand Down
24 changes: 24 additions & 0 deletions packages/ckeditor5-image/tests/imageresize/imageresizeediting.js
Expand Up @@ -491,6 +491,30 @@ describe( 'ImageResizeEditing', () => {
expect( newEditor.model.schema.checkAttribute( [ '$root', 'imageInline' ], 'resizedHeight' ) ).to.be.true;
await newEditor.destroy();
} );

it( 'allows the resizedWidth attribute when ImageBlock plugin is enabled (reverse order in plugins array)', async () => {
const newEditor = await ClassicEditor.create( editorElement, { plugins: [ ImageResizeEditing, ImageBlockEditing ] } );
expect( newEditor.model.schema.checkAttribute( [ '$root', 'imageBlock' ], 'resizedWidth' ) ).to.be.true;
await newEditor.destroy();
} );

it( 'allows the resizedHeight attribute when ImageBlock plugin is enabled (reverse order in plugins array)', async () => {
const newEditor = await ClassicEditor.create( editorElement, { plugins: [ ImageResizeEditing, ImageBlockEditing ] } );
expect( newEditor.model.schema.checkAttribute( [ '$root', 'imageBlock' ], 'resizedHeight' ) ).to.be.true;
await newEditor.destroy();
} );

it( 'allows the resizedWidth attribute when ImageInline plugin is enabled (reverse order in plugins array)', async () => {
const newEditor = await ClassicEditor.create( editorElement, { plugins: [ ImageResizeEditing, ImageInlineEditing ] } );
expect( newEditor.model.schema.checkAttribute( [ '$root', 'imageInline' ], 'resizedWidth' ) ).to.be.true;
await newEditor.destroy();
} );

it( 'allows the resizedHeight attribute when ImageInline plugin is enabled (reverse order in plugins array)', async () => {
const newEditor = await ClassicEditor.create( editorElement, { plugins: [ ImageResizeEditing, ImageInlineEditing ] } );
expect( newEditor.model.schema.checkAttribute( [ '$root', 'imageInline' ], 'resizedHeight' ) ).to.be.true;
await newEditor.destroy();
} );
} );

describe( 'command', () => {
Expand Down

0 comments on commit de65bbd

Please sign in to comment.