diff --git a/addons/web_editor/static/lib/odoo-editor/src/OdooEditor.js b/addons/web_editor/static/lib/odoo-editor/src/OdooEditor.js index ab4ba780854..1ee442858d7 100644 --- a/addons/web_editor/static/lib/odoo-editor/src/OdooEditor.js +++ b/addons/web_editor/static/lib/odoo-editor/src/OdooEditor.js @@ -209,6 +209,7 @@ export class OdooEditor extends EventTarget { return closestElement(selection.anchorNode, 'P, DIV'); } }, + preHistoryUndo: () => {}, isHintBlacklisted: () => false, filterMutationRecords: (records) => records, direction: 'ltr', @@ -809,6 +810,7 @@ export class OdooEditor extends EventTarget { * "consumed": The position has been undone and is considered consumed. */ historyUndo() { + this.options.preHistoryUndo(); // The last step is considered an uncommited draft so always revert it. const lastStep = this._currentStep; this.historyRevert(lastStep); 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 6c00e81ba9c..0573494e273 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/link.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/link.js @@ -19,6 +19,7 @@ const Link = Widget.extend({ 'input': '_onAnyChange', 'change': '_onAnyChange', 'input input[name="url"]': '_onURLInput', + 'change input[name="url"]': '_onURLInputChange', }, /** @@ -142,6 +143,7 @@ const Link = Widget.extend({ var match = /mailto:(.+)/.exec(this.data.url); this.$('input[name="url"]').val(match ? match[1] : this.data.url); this._onURLInput(); + this._savedURLInputOnDestroy = false; } this._updateOptionsUI(); @@ -152,6 +154,15 @@ const Link = Widget.extend({ return this._super.apply(this, arguments); }, + /** + * @override + */ + destroy () { + if (this._savedURLInputOnDestroy) { + this._adaptPreview(); + } + this._super(...arguments); + }, //-------------------------------------------------------------------------- // Public @@ -458,19 +469,26 @@ const Link = Widget.extend({ /** * @private */ - _onAnyChange: function () { - this._adaptPreview(); + _onAnyChange: function (e) { + if (!e.target.closest('input[type="text"]')) { + this._adaptPreview(); + } }, /** * @private */ _onURLInput: function () { + this._savedURLInputOnDestroy = true; var $linkUrlInput = this.$('#o_link_dialog_url_input'); let value = $linkUrlInput.val(); let isLink = value.indexOf('@') < 0; this.$('input[name="is_new_window"]').closest('.form-group').toggleClass('d-none', !isLink); this.$('.o_strip_domain').toggleClass('d-none', value.indexOf(window.location.origin) !== 0); }, + _onURLInputChange: function () { + this._adaptPreview(); + this._savedURLInputOnDestroy = false; + }, }); /** 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 e7abba60cf7..08631fcb1b8 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 @@ -45,31 +45,28 @@ const LinkTools = Link.extend({ * @override */ start: function () { - this.$link.addClass('oe_edited_link'); - this.$button.addClass('active'); + this._addHintClasses(); return this._super(...arguments); }, destroy: function () { if (!this.el) { return this._super(...arguments); } - $(this.options.wysiwyg.odooEditor.document).find('.oe_edited_link').removeClass('oe_edited_link'); const $contents = this.$link.contents(); if (!this.$link.attr('href') && !this.colorCombinationClass) { $contents.unwrap(); } - this.$button.removeClass('active'); - this.applyLinkToDom(this._getData()); - if (!this.options.wysiwyg.odooEditor.isDestroyed) { - this.options.wysiwyg.odooEditor.historyStep(); - } this._observer.disconnect(); this._super(...arguments); + this._removeHintClasses(); }, applyLinkToDom() { this._observer.disconnect(); + this._removeHintClasses(); this._super(...arguments); + this.options.wysiwyg.odooEditor.historyStep(); + this._addHintClasses(); this._observer.observe(this._link, {subtree: true, childList: true, characterData: true}); }, @@ -97,7 +94,6 @@ const LinkTools = Link.extend({ if (data === null) { return; } - data.classes += ' oe_edited_link'; this.applyLinkToDom(data); }, /** @@ -323,6 +319,24 @@ const LinkTools = Link.extend({ $colorPreview.css('background-image', isColorGradient(color) ? color : ''); } }, + /** + * Add hint to the classes of the link and button. + */ + _addHintClasses () { + this.options.wysiwyg.odooEditor.observerUnactive("hint_classes"); + this.$link.addClass('oe_edited_link'); + this.$button.addClass('active'); + this.options.wysiwyg.odooEditor.observerActive("hint_classes"); + }, + /** + * Remove hint to the classes of the link and button. + */ + _removeHintClasses () { + this.options.wysiwyg.odooEditor.observerUnactive("hint_classes"); + $(this.options.wysiwyg.odooEditor.document).find('.oe_edited_link').removeClass('oe_edited_link'); + this.$button.removeClass('active'); + this.options.wysiwyg.odooEditor.observerActive("hint_classes"); + }, //-------------------------------------------------------------------------- // Handlers diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index cadf73a20fe..10b8b95f5ed 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -163,6 +163,12 @@ const Wysiwyg = Widget.extend({ return !(record.target.classList && record.target.classList.contains('o_header_standard')); }); }, + preHistoryUndo: () => { + if (this.linkTools) { + this.linkTools.destroy(); + this.linkTools = undefined; + } + }, commands: commands, plugins: options.editorPlugins, direction: localization.direction || 'ltr',