Skip to content

Commit

Permalink
Update width and height.
Browse files Browse the repository at this point in the history
  • Loading branch information
illia-stv committed Oct 16, 2023
1 parent 1981593 commit 555b38c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/ckeditor5-image/src/image/replaceimagesourcecommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { Command, type Editor } from 'ckeditor5/src/core';
import type ImageUtils from '../imageutils';
import ImageUtils from '../imageutils';
import type { Writer, Element } from 'ckeditor5/src/engine';

/**
Expand All @@ -29,6 +29,13 @@ export default class ReplaceImageSourceCommand extends Command {
this.decorate( 'cleanupImage' );
}

/**
* @inheritDoc
*/
public static get requires() {
return [ ImageUtils ] as const;
}

/**
* @inheritDoc
*/
Expand All @@ -50,12 +57,15 @@ export default class ReplaceImageSourceCommand extends Command {
*/
public override execute( options: { source: string } ): void {
const image = this.editor.model.document.selection.getSelectedElement()!;
const imageUtils: ImageUtils = this.editor.plugins.get( 'ImageUtils' );

this.editor.model.change( writer => {
writer.setAttribute( 'src', options.source, image );

this.cleanupImage( writer, image );
} );

imageUtils.setImageNaturalSizeAttributes( image );
}

/**
Expand Down

0 comments on commit 555b38c

Please sign in to comment.