From d9eeb6ab9b1445e568a6efd0575e2b6941149d43 Mon Sep 17 00:00:00 2001 From: Lucas Perais Date: Wed, 12 Jul 2023 09:15:41 +0000 Subject: [PATCH] [FIX] web_editor: wysiwyg, QWebPlugin: use getContextFromParentRect from options Before this commit, the option getContextFromParentRect was not used to compute the position of the branching in the QwebPlugin. Also, the Wysiwyg forced that callback in the options. This commit fixes those two issues Part-of: odoo/odoo#128228 --- addons/web_editor/static/src/js/backend/QWebPlugin.js | 9 +++++++-- .../web_editor/static/src/js/wysiwyg/wysiwyg_iframe.js | 8 +++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/addons/web_editor/static/src/js/backend/QWebPlugin.js b/addons/web_editor/static/src/js/backend/QWebPlugin.js index f6b316dc0a6..897c811cb82 100644 --- a/addons/web_editor/static/src/js/backend/QWebPlugin.js +++ b/addons/web_editor/static/src/js/backend/QWebPlugin.js @@ -12,6 +12,7 @@ export class QWebPlugin { this._editable = this._options.editable; this._document = this._options.document || window.document; } + this._getContextFromParentRect = this._options.editor?.options?.getContextFromParentRect || (() => ({ top: 0, left: 0 })); this._editable = this._options.editable || (this._options.editor && this._options.editor.editable); this._document = this._options.document || (this._options.editor && this._options.editor.document) || window.document; this._tGroupCount = 0; @@ -183,9 +184,13 @@ export class QWebPlugin { const box = target.getBoundingClientRect(); const selBox = this._selectElWrapper.getBoundingClientRect(); + const parentBox = this._getContextFromParentRect(); - this._selectElWrapper.style.left = `${window.scrollX + box.left}px`; - this._selectElWrapper.style.top = `${window.scrollY + box.top - selBox.height}px`; + const left = parentBox.left + window.scrollX + box.left; + const top = parentBox.top + window.scrollY + box.top - selBox.height; + + this._selectElWrapper.style.left = `${left}px`; + this._selectElWrapper.style.top = `${top}px`; } _renderBranchingSelection(target) { const selectEl = document.createElement('select'); diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg_iframe.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg_iframe.js index a027abeb13a..e2702691b0f 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg_iframe.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg_iframe.js @@ -48,9 +48,11 @@ patch(Wysiwyg.prototype, 'wysiwyg_iframe.js', { **/ _getEditorOptions() { const options = this._super.apply(this, arguments); - options.getContextFromParentRect = () => { - return this.$iframe && this.$iframe.length ? this.$iframe[0].getBoundingClientRect() : { top: 0, left: 0 }; - }; + if (!("getContextFromParentRect" in options)) { + options.getContextFromParentRect = () => { + return this.$iframe && this.$iframe.length ? this.$iframe[0].getBoundingClientRect() : { top: 0, left: 0 }; + }; + } return options; }, /**