diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/link.js b/addons/web_editor/static/src/js/wysiwyg/widgets/link.js index 08bb9e31617..1432850ff7c 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/link.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/link.js @@ -31,6 +31,8 @@ const Link = Widget.extend({ title: _t("Link to"), }, this.options)); + this._setLinkContent = true; + this.data = data || {}; this.isButton = this.data.isButton; this.$button = $button; @@ -201,7 +203,7 @@ const Link = Widget.extend({ if (!this.$link.attr('target')) { this.$link[0].removeAttribute('target'); } - if (data.content !== this.data.originalText || data.url !== this.data.url) { + if (this._setLinkContent && (data.content !== this.data.originalText || data.url !== this.data.url)) { const content = (data.content && data.content.length) ? data.content : data.url; // If there is a this.data.originalText, it means that we selected // the text and we could not change the content through the text 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 185c8d2e75f..0dd67dcebd9 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 @@ -4,7 +4,6 @@ odoo.define('wysiwyg.widgets.LinkTools', function (require) { const Link = require('wysiwyg.widgets.Link'); const {ColorPaletteWidget} = require('web_editor.ColorPalette'); const {ColorpickerWidget} = require('web.Colorpicker'); -const OdooEditorLib = require('@web_editor/../lib/odoo-editor/src/OdooEditor'); const dom = require('web.dom'); const { computeColorClasses, @@ -14,8 +13,6 @@ const { isColorGradient, } = require('web_editor.utils'); -const setSelection = OdooEditorLib.setSelection; - /** * Allows to customize link content and style. */ @@ -37,8 +34,13 @@ const LinkTools = Link.extend({ $(node).wrap(''); node = node.parentElement; } - const link = node || this.getOrCreateLink(editable); - this._super(parent, options, editable, data, $button, link); + this._link = node || this.getOrCreateLink(editable); + this._observer = new MutationObserver(() =>{ + this._setLinkContent = false; + this._observer.disconnect(); + }); + this._observer.observe(this._link, {subtree: true, childList: true, characterData: true}); + this._super(parent, options, editable, data, $button, this._link); // Keep track of each selected custom color and colorpicker. this.customColors = {}; this.colorpickers = {}; @@ -70,9 +72,16 @@ const LinkTools = Link.extend({ this.options.wysiwyg.odooEditor.observerActive(); this.applyLinkToDom(this._getData()); this.options.wysiwyg.odooEditor.historyStep(); + this._observer.disconnect(); this._super(...arguments); }, + applyLinkToDom() { + this._observer.disconnect(); + this._super(...arguments); + this._observer.observe(this._link, {subtree: true, childList: true, characterData: true}); + }, + //-------------------------------------------------------------------------- // Private //--------------------------------------------------------------------------