Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Fix: DOM should be re–painted upon image upload in Safari to make sur…
Browse files Browse the repository at this point in the history
…e the image has the right size. Closes ckeditor/ckeditor5#1975.
  • Loading branch information
oleq committed Aug 20, 2019
1 parent 9bf4b35 commit 23a110b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/imageupload/imageuploadediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import FileRepository from '@ckeditor/ckeditor5-upload/src/filerepository';
import Notification from '@ckeditor/ckeditor5-ui/src/notification/notification';
import UpcastWriter from '@ckeditor/ckeditor5-engine/src/view/upcastwriter';
import env from '@ckeditor/ckeditor5-utils/src/env';

import ImageUploadCommand from '../../src/imageupload/imageuploadcommand';
import { isImageType, isLocalImage, fetchLocalImage } from '../../src/imageupload/utils';
Expand Down Expand Up @@ -192,6 +193,23 @@ export default class ImageUploadEditing extends Plugin {
const viewImg = viewFigure.getChild( 0 );
const promise = loader.upload();

// Force re–paint in Safari. Without it, the image will display with a wrong size.
// https://github.com/ckeditor/ckeditor5/issues/1975
if ( env.isSafari ) {
editor.ui.once( 'update', () => {
const domFigure = editor.editing.view.domConverter.viewToDom( viewImg.parent );
const originalDisplay = domFigure.style.display;

domFigure.style.display = 'none';

const offsetHeightBefore = domFigure.offsetHeight; // eslint-disable-line no-unused-vars

domFigure.style.display = originalDisplay;

const offsetHeightAfter = domFigure.offsetHeight; // eslint-disable-line no-unused-vars
} );
}

editor.editing.view.change( writer => {
writer.setAttribute( 'src', data, viewImg );
} );
Expand Down

0 comments on commit 23a110b

Please sign in to comment.