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

Commit 8e14b03

Browse files
authoredAug 20, 2019
Merge pull request #311 from ckeditor/t/ckeditor5/1975b
Fix: Worked around Safari's image size bug. Closes ckeditor/ckeditor5#1975.
2 parents 9bf4b35 + 26ce76e commit 8e14b03

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
 

‎src/imageupload/imageuploadediting.js

+29
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
1111
import FileRepository from '@ckeditor/ckeditor5-upload/src/filerepository';
1212
import Notification from '@ckeditor/ckeditor5-ui/src/notification/notification';
1313
import UpcastWriter from '@ckeditor/ckeditor5-engine/src/view/upcastwriter';
14+
import env from '@ckeditor/ckeditor5-utils/src/env';
1415

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

196+
// Force re–paint in Safari. Without it, the image will display with a wrong size.
197+
// https://github.com/ckeditor/ckeditor5/issues/1975
198+
/* istanbul ignore next */
199+
if ( env.isSafari ) {
200+
editor.editing.view.once( 'render', () => {
201+
// Early returns just to be safe. There might be some code ran
202+
// in between the outer scope and this callback.
203+
if ( !viewImg.parent ) {
204+
return;
205+
}
206+
207+
const domFigure = editor.editing.view.domConverter.mapViewToDom( viewImg.parent );
208+
209+
if ( !domFigure ) {
210+
return;
211+
}
212+
213+
const originalDisplay = domFigure.style.display;
214+
215+
domFigure.style.display = 'none';
216+
217+
// Make sure this line will never be removed during minification for having "no effect".
218+
domFigure._ckHack = domFigure.offsetHeight;
219+
220+
domFigure.style.display = originalDisplay;
221+
} );
222+
}
223+
195224
editor.editing.view.change( writer => {
196225
writer.setAttribute( 'src', data, viewImg );
197226
} );

0 commit comments

Comments
 (0)
This repository has been archived.