From 00025dd406b8b7b6322672000e0d6401d769e73c Mon Sep 17 00:00:00 2001 From: Benjamin Vray Date: Thu, 22 Jul 2021 12:52:06 +0000 Subject: [PATCH] [FIX] web, web_editor: disable horizontal scroll when dragging snippet This commit adds an option to disable horizontal scrolling in the smoothScrollOnDrag feature options and use it when dragging and dropping a snippet into the editor to prevent the wrapwrap from scrolling horizontally when an element overflow the page (e.g. an animated element). task-2215118 closes odoo/odoo#74518 X-original-commit: fdbc109780f336c4b7dcac31585beaad682e029a Signed-off-by: Quentin Smetz (qsm) --- .../src/legacy/js/core/smooth_scroll_on_drag.js | 12 ++++++++---- .../static/src/js/editor/snippets.editor.js | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/addons/web/static/src/legacy/js/core/smooth_scroll_on_drag.js b/addons/web/static/src/legacy/js/core/smooth_scroll_on_drag.js index 28a4beff4c4..37aae5f1f44 100644 --- a/addons/web/static/src/legacy/js/core/smooth_scroll_on_drag.js +++ b/addons/web/static/src/legacy/js/core/smooth_scroll_on_drag.js @@ -90,6 +90,7 @@ const SmoothScrollOnDrag = Class.extend(mixins.ParentedMixin, { * @param {jQuery} [options.offsetElements.$left] Visible left offset element which width * will be taken into account when triggering scroll at the left side of the * $scrollTarget. + * @param {boolean} [options.disableHorizontalScroll = false] Disable horizontal scroll if not needed. */ init(parent, $element, $scrollTarget, options = {}) { mixins.ParentedMixin.init.call(this); @@ -126,6 +127,7 @@ const SmoothScrollOnDrag = Class.extend(mixins.ParentedMixin, { }; this.options.jQueryDraggableOptions.scroll = false; + this.options.disableHorizontalScroll = this.options.disableHorizontalScroll || false; const draggableOptions = Object.assign({}, this.options.jQueryDraggableOptions, { start: (ev, ui) => this._onSmoothDragStart(ev, ui, this.options.jQueryDraggableOptions.start), drag: (ev, ui) => this._onSmoothDrag(ev, ui, this.options.jQueryDraggableOptions.drag), @@ -203,10 +205,12 @@ const SmoothScrollOnDrag = Class.extend(mixins.ParentedMixin, { this.$scrollTarget.scrollTop() + this.verticalDelta ); - this.$scrollTarget.scrollLeft( - this.$scrollTarget.scrollLeft() + - this.horizontalDelta - ); + if (!this.options.disableHorizontalScroll) { + this.$scrollTarget.scrollLeft( + this.$scrollTarget.scrollLeft() + + this.horizontalDelta + ); + } }, this.options.scrollTimerInterval ); diff --git a/addons/web_editor/static/src/js/editor/snippets.editor.js b/addons/web_editor/static/src/js/editor/snippets.editor.js index 73afcc1f3cf..c8990657713 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -2182,6 +2182,7 @@ var SnippetsMenu = Widget.extend({ greedy: true, scroll: false, }, options.jQueryDraggableOptions), + disableHorizontalScroll: true, }); }, /**