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 f38b38767ad12296f5c3d2315461ecd6554d32b5..577132a6f279c05b6b02c86cba3b8569a65c51f6 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -1079,7 +1079,7 @@ var SnippetsMenu = Widget.extend({ // Hide the active overlay when scrolling. // Show it again and recompute all the overlays after the scroll. this.$scrollingElement = $().getScrollingElement(); - this.$scrollingElement.on('scroll.snippets_menu', _.throttle(() => { + this._onScrollingElementScroll = _.throttle(() => { for (const editor of this.snippetEditors) { editor.toggleOverlayVisibility(false); } @@ -1091,7 +1091,12 @@ var SnippetsMenu = Widget.extend({ editor.cover(); } }, 250); - }, 50)); + }, 50) + // We use addEventListener instead of jQuery because we need 'capture'. + // Setting capture to true allows to take advantage of event bubbling + // for events that otherwise don’t support it. (e.g. useful when + // scrolling a modal) + this.$scrollingElement[0].addEventListener('scroll', this._onScrollingElementScroll, {capture: true}); // Auto-selects text elements with a specific class and remove this // on text changes @@ -1156,7 +1161,7 @@ var SnippetsMenu = Widget.extend({ this.$snippetEditorArea.remove(); this.$window.off('.snippets_menu'); this.$document.off('.snippets_menu'); - this.$scrollingElement.off('.snippets_menu'); + this.$scrollingElement[0].removeEventListener('scroll', this._onScrollingElementScroll, {capture: true}); } core.bus.off('deactivate_snippet', this, this._onDeactivateSnippet); delete this.cacheSnippetTemplate[this.options.snippets];