FIX: Return `naturalWidth` and `naturalHeight` for Composer image sizes (#13271)

Rather than returning the size of the currently rendered image in the composer window (which is dependent on browser settings such as window size and zoom level), return the actual dimensions of the image file itself.

(Also see commit abac614492 which was an earlier attempt to fix this by excluding Oneboxed images entirely. That was reverted as the CSS selector didn’t work on all browsers.)
This commit is contained in:
jbrw 2021-06-03 16:21:56 -04:00 committed by GitHub
parent 9a449ac534
commit 9d8bc6a405
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 7 deletions

View File

@ -770,12 +770,13 @@ export default Controller.extend({
// TODO: This should not happen in model
const imageSizes = {};
$("#reply-control .d-editor-preview img").each((i, e) => {
const $img = $(e);
const src = $img.prop("src");
document
.querySelectorAll("#reply-control .d-editor-preview img")
.forEach((e) => {
const src = e.src;
if (src && src.length) {
imageSizes[src] = { width: $img.width(), height: $img.height() };
imageSizes[src] = { width: e.naturalWidth, height: e.naturalHeight };
}
});