diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/link_tools.js b/addons/web_editor/static/src/js/wysiwyg/widgets/link_tools.js index ad1533e2a7e..14f787c2a6c 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/link_tools.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/link_tools.js @@ -68,7 +68,6 @@ const LinkTools = Link.extend({ this.$button.removeClass('active'); this.options.wysiwyg.odooEditor.observerActive(); this.applyLinkToDom(this._getData()); - setSelection(this.$link[0], 0, this.$link[0], 1); this.options.wysiwyg.odooEditor.historyStep(); this._super(...arguments); }, diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index 60cbd039f8c..d1b3820b3c9 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -886,16 +886,19 @@ const Wysiwyg = Widget.extend({ return; } if (this.snippetsMenu && !options.forceDialog) { - if (this.linkTools) { - this.linkTools.destroy(); - } if (options.forceOpen || !this.linkTools) { const $btn = this.toolbar.$el.find('#create-link'); - this.linkTools = new weWidgets.LinkTools(this, {wysiwyg: this, noFocusUrl: options.noFocusUrl}, this.odooEditor.editable, {}, $btn, options.link || this.lastMediaClicked); + if (!this.linkTools || ![options.link, ...wysiwygUtils.ancestors(options.link)].includes(this.linkTools.$link[0])) { + this.linkTools = new weWidgets.LinkTools(this, {wysiwyg: this, noFocusUrl: options.noFocusUrl}, this.odooEditor.editable, {}, $btn, options.link || this.lastMediaClicked); + } const _onMousedown = ev => { - if (!ev.target.closest('.oe-toolbar') && !ev.target.closest('.ui-autocomplete')) { + if ( + !ev.target.closest('.oe-toolbar') && + !ev.target.closest('.ui-autocomplete') && + (!this.linkTools || ![ev.target, ...wysiwygUtils.ancestors(ev.target)].includes(this.linkTools.$link[0])) + ) { // Destroy the link tools on click anywhere outside the - // toolbar. + // toolbar if the target is the orgiginal target not in the original target. this.linkTools && this.linkTools.destroy(); this.linkTools = undefined; this.odooEditor.document.removeEventListener('mousedown', _onMousedown, true); @@ -904,6 +907,7 @@ const Wysiwyg = Widget.extend({ this.odooEditor.document.addEventListener('mousedown', _onMousedown, true); this.linkTools.appendTo(this.toolbar.$el); } else { + this.linkTools.destroy(); this.linkTools = undefined; } } else { diff --git a/addons/web_editor/static/src/scss/wysiwyg.scss b/addons/web_editor/static/src/scss/wysiwyg.scss index eee6ebaeef5..e09022331b3 100644 --- a/addons/web_editor/static/src/scss/wysiwyg.scss +++ b/addons/web_editor/static/src/scss/wysiwyg.scss @@ -440,6 +440,7 @@ body:not(.editor_has_snippets) { border: dashed 3px #01bad2; position: absolute; inset: -5px; + pointer-events: none; } }