[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
This commit is contained in:
Lucas Perais
2023-07-20 17:01:32 +02:00
parent e792eb10f0
commit d9eeb6ab9b
2 changed files with 12 additions and 5 deletions
@@ -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');
@@ -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;
},
/**