From d0bd894526cbeece2fe267e1747f505d4774330f Mon Sep 17 00:00:00 2001
From: Tim Bozeman <tim@timbozeman.com>
Date: Wed, 12 Mar 2025 12:42:04 -0700
Subject: [PATCH] Fix media edits sometime not being centered

---
 js/edit_plus/plugins/field-plugin-base.js | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/js/edit_plus/plugins/field-plugin-base.js b/js/edit_plus/plugins/field-plugin-base.js
index 6bd5072..f7e4094 100644
--- a/js/edit_plus/plugins/field-plugin-base.js
+++ b/js/edit_plus/plugins/field-plugin-base.js
@@ -338,13 +338,16 @@ export class FieldPluginBase {
     sizedPlaceholder.classList.add('sized-placeholder');
     pageElement.parentElement.insertBefore(sizedPlaceholder, pageElement);
 
-    this.positionFormItemOverPageElement();
-    document.addEventListener('scroll', this.positionFormItemOverPageElement);
-    window.addEventListener('resize', this.positionFormItemOverPageElement);
+    pageElement.classList.add('edit-plus-hidden');
+    formItem.classList.add('edit-plus-editing');
 
     // Make the sized placeholder the same height as the form item.
     sizedPlaceholder.style.height = formItem.getBoundingClientRect().height + 'px';
 
+    this.positionFormItemOverPageElement();
+    document.addEventListener('scroll', this.positionFormItemOverPageElement);
+    window.addEventListener('resize', this.positionFormItemOverPageElement);
+
     // Ensure the sizedPlaceholder height stays in sync with the formItem height.
     // As items are added or removed from the form item via ajax, the sizedPlaceholder
     // should grow or shrink accordingly.
@@ -358,8 +361,6 @@ export class FieldPluginBase {
     });
     Drupal.EditPlus.CurrentlyEditingElement.sizedPlaceholderHeightObserver.observe(formItem);
 
-    pageElement.classList.add('edit-plus-hidden');
-    formItem.classList.add('edit-plus-editing');
     formItem.classList.remove('edit-plus-hidden');
   }
 
-- 
GitLab