Skip to content

Commit be8cc87

Browse files
[FIX] web: NO SQUASH, position and scrolling issue
[FIX] html_editor (position and scrolling issue) DO NOT SQUASH: very specific fix for overlay_buttons_plugin move on scroll [FIX] fixed the scroll offset
1 parent 057b80e commit be8cc87

File tree

5 files changed

+22
-11
lines changed

5 files changed

+22
-11
lines changed

addons/html_builder/static/src/sidebar/block_tab.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ export class BlockTab extends Component {
218218
el: this.blockTabRef.el,
219219
elements: ".o_snippet.o_draggable",
220220
scrollingElement,
221+
externalScroll: () => Boolean(this.props.getExternalScrollableAncestor?.()),
221222
handle: ".o_snippet_thumbnail:not(.o_we_ongoing_insertion .o_snippet_thumbnail)",
222223
dropzones: () => dropzoneEls,
223224
helper: ({ element, helperOffset }) => {

addons/html_editor/static/src/core/overlay_plugin.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { markRaw, EventBus } from "@odoo/owl";
22
import { Plugin } from "../plugin";
33
import { EditorOverlay } from "./overlay";
44
import { throttleForAnimation } from "@web/core/utils/timing";
5-
import { findUpTo } from "@html_editor/utils/dom_traversal";
5+
import { closestScrollableY } from "@web/core/utils/scrolling";
66

77
/**
88
* @typedef { Object } OverlayShared
@@ -56,14 +56,7 @@ export class OverlayPlugin extends Plugin {
5656
}
5757

5858
getScrollContainer() {
59-
const isScrollable = (element) =>
60-
element.scrollHeight > element.clientHeight &&
61-
["auto", "scroll"].includes(getComputedStyle(element).overflowY);
62-
63-
return (
64-
findUpTo(this.iframe || this.editable, null, isScrollable) ||
65-
this.topDocument.documentElement
66-
);
59+
return closestScrollableY(this.iframe || this.editable) || this.topDocument.documentElement;
6760
}
6861
}
6962

addons/html_editor/static/src/utils/drag_and_drop.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ const dragAndDropHookParams = {
102102
scrollingElement: [Function],
103103
helper: [Function],
104104
extraWindow: [Object, Function],
105+
externalScroll: [Function],
105106
},
106107
edgeScrolling: { enabled: true },
107108
onComputeParams({ ctx, params }) {
@@ -110,10 +111,18 @@ const dragAndDropHookParams = {
110111
ctx.getScrollingElement = params.scrollingElement;
111112
ctx.getHelper = params.helper;
112113
ctx.getDropZones = params.dropzones;
114+
ctx.hasExternalScroll = params.externalScroll;
113115
},
114116
onWillStartDrag: ({ ctx }) => {
115117
ctx.current.container = ctx.getScrollingElement();
116-
ctx.current.helperOffset = { x: 0, y: 0 };
118+
ctx.current.hasExternalScroll = ctx.hasExternalScroll();
119+
ctx.current.helperOffset = {
120+
x: 0,
121+
y: 0,
122+
originalScrollTop: ctx.current.hasExternalScroll
123+
? ctx.getScrollingElement().scrollTop
124+
: 0,
125+
};
117126
},
118127
onDragStart: ({ ctx, addStyle, addCleanup }) => {
119128
// Use the helper as the tracking element to properly update scroll values.
@@ -145,10 +154,12 @@ const dragAndDropHookParams = {
145154
updateElementPosition(ctx.current.helper, ctx.pointer, addStyle, ctx.current.helperOffset);
146155
// Unfortunately, DOMRect is not an Object, so spreading operator from
147156
// `touching` does not work, so convert DOMRect to plain object.
157+
const scrollOffset =
158+
ctx.current.container.scrollTop - ctx.current.helperOffset.originalScrollTop;
148159
let helperRect = ctx.current.helper.getBoundingClientRect();
149160
helperRect = {
150161
x: helperRect.x,
151-
y: helperRect.y,
162+
y: helperRect.y + (ctx.current.hasExternalScroll ? scrollOffset : 0),
152163
width: helperRect.width,
153164
height: helperRect.height,
154165
};

addons/mass_mailing_egg/static/src/iframe/mass_mailing_iframe.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ export class MassMailingIframe extends Component {
289289
// Plugins => provide plugins selection, properly filter excluded Plugins
290290
isMobile: this.state.isMobile,
291291
toggleMobile: () => {
292+
this.iframeRef.el.contentDocument.body.scrollTop = 0;
292293
this.state.isMobile = !this.state.isMobile;
293294
this.throttledResize();
294295
},

addons/web/static/src/core/position/position_hook.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,15 @@ export function usePosition(refName, getTarget, options = {}) {
9797
const targetDocument = getTarget()?.ownerDocument;
9898
targetDocument?.addEventListener("scroll", scrollListener, { capture: true });
9999
targetDocument?.addEventListener("load", throttledUpdate, { capture: true });
100+
const containerDocument = options.container?.()?.ownerDocument;
101+
containerDocument?.addEventListener("scroll", scrollListener, { capture: true });
102+
containerDocument?.addEventListener("load", throttledUpdate, { capture: true });
100103
window.addEventListener("resize", throttledUpdate);
101104
return () => {
102105
targetDocument?.removeEventListener("scroll", scrollListener, { capture: true });
103106
targetDocument?.removeEventListener("load", throttledUpdate, { capture: true });
107+
containerDocument?.removeEventListener("scroll", scrollListener, { capture: true });
108+
containerDocument?.removeEventListener("load", throttledUpdate, { capture: true });
104109
window.removeEventListener("resize", throttledUpdate);
105110
};
106111
}

0 commit comments

Comments
 (0)