[FIX] web_editor: powerbox overflow not visible

Before this commit:

In Email Marketing's Mail Body, The Powerbox is opened below the cursor,
even when there's not enough space between the cursor line and
the window's bottom. As a result, a part of the Powerbox cannot be seen.

After this commit:

Now, the Powerbox opens itself above the cursor line if it's too close to the
window's bottom.

Task-3037435

closes odoo/odoo#108352

X-original-commit: ba888c39716f0226adce993cb08852e21b0376eb
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
This commit is contained in:
dhba-odoo
2022-12-20 12:33:48 +01:00
parent f16d37b6d4
commit 3ec95bba96
2 changed files with 10 additions and 6 deletions
@@ -272,14 +272,13 @@ export class Powerbox {
* @private
*/
_resetPosition() {
const position = getRangePosition(this.el, this.document);
let options = {};
if (this.getContextFromParentRect) {
options['parentContextRect'] = this.getContextFromParentRect();
}
const position = getRangePosition(this.el, this.document, options);
if (position) {
let { left, top } = position;
if (this.getContextFromParentRect) {
const parentContextRect = this.getContextFromParentRect();
left += parentContextRect.left;
top += parentContextRect.top;
}
this.el.style.left = `${left}px`;
this.el.style.top = `${top}px`;
} else {
@@ -2525,6 +2525,11 @@ export function getRangePosition(el, document, options = {}) {
offset.left = marginLeft;
}
if (options.parentContextRect) {
offset.left += options.parentContextRect.left;
offset.top += options.parentContextRect.top;
}
if (
offset.top - marginTop + offset.height + el.offsetHeight > window.innerHeight &&
offset.top - el.offsetHeight - marginBottom > 0