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

Commit

Permalink
Merge pull request #311 from ckeditor/t/ckeditor5/1975b
Browse files Browse the repository at this point in the history
Fix: Worked around Safari's image size bug. Closes ckeditor/ckeditor5#1975.
  • Loading branch information
Reinmar authored Aug 20, 2019
2 parents 9bf4b35 + 26ce76e commit 8e14b03
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 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,34 @@ 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
/* istanbul ignore next */
if ( env.isSafari ) {
editor.editing.view.once( 'render', () => {
// Early returns just to be safe. There might be some code ran
// in between the outer scope and this callback.
if ( !viewImg.parent ) {
return;
}

const domFigure = editor.editing.view.domConverter.mapViewToDom( viewImg.parent );

if ( !domFigure ) {
return;
}

const originalDisplay = domFigure.style.display;

domFigure.style.display = 'none';

// Make sure this line will never be removed during minification for having "no effect".
domFigure._ckHack = domFigure.offsetHeight;

domFigure.style.display = originalDisplay;
} );
}

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

0 comments on commit 8e14b03

Please sign in to comment.