diff --git a/addons/mass_mailing/static/src/js/wysiwyg.js b/addons/mass_mailing/static/src/js/wysiwyg.js index e827a10797e..4fd836b9a3c 100644 --- a/addons/mass_mailing/static/src/js/wysiwyg.js +++ b/addons/mass_mailing/static/src/js/wysiwyg.js @@ -3,6 +3,7 @@ odoo.define('mass_mailing.wysiwyg', function (require) { var Wysiwyg = require('web_editor.wysiwyg'); var MassMailingSnippetsMenu = require('mass_mailing.snippets.editor'); +const {closestElement} = require('@web_editor/../lib/odoo-editor/src/OdooEditor'); const MassMailingWysiwyg = Wysiwyg.extend({ //-------------------------------------------------------------------------- @@ -38,13 +39,38 @@ const MassMailingWysiwyg = Wysiwyg.extend({ */ _getCommands: function () { const commands = this._super(); - const linkCommand = commands.find(command => command.title === 'Link'); - if (linkCommand) { + const linkCommands = commands.filter(command => command.title === 'Link' || command.title === 'Button'); + for (const linkCommand of linkCommands) { // Don't open the dialog: use the link tools. linkCommand.callback = () => this.toggleLinkTools({forceDialog: false}); + // Remove the command if the selection is within a background-image. + const superIsDisabled = linkCommand.isDisabled; + linkCommand.isDisabled = () => { + if (superIsDisabled && superIsDisabled()) { + return true; + } else { + const selection = this.odooEditor.document.getSelection(); + const range = selection.rangeCount && selection.getRangeAt(0); + return !!range && !!closestElement(range.startContainer, '[style*=background-image]'); + } + } } return commands; }, + /** + * @override + */ + _updateEditorUI: function (e) { + this._super(...arguments); + // Hide the create-link button if the selection is within a + // background-image. + const selection = this.odooEditor.document.getSelection(); + const range = selection.rangeCount && selection.getRangeAt(0); + const isWithinBackgroundImage = !!range && !!closestElement(range.startContainer, '[style*=background-image]'); + if (isWithinBackgroundImage) { + this.toolbar.$el.find('#create-link').toggleClass('d-none', true); + } + }, }); return MassMailingWysiwyg; diff --git a/addons/web_editor/static/lib/odoo-editor/src/powerbox/Powerbox.js b/addons/web_editor/static/lib/odoo-editor/src/powerbox/Powerbox.js index 812f7af3ef8..0088dd05a6b 100644 --- a/addons/web_editor/static/lib/odoo-editor/src/powerbox/Powerbox.js +++ b/addons/web_editor/static/lib/odoo-editor/src/powerbox/Powerbox.js @@ -56,6 +56,9 @@ export class Powerbox { clearTimeout(this._renderingTimeout); this._hoverActive = false; + // Do not show disabled commands. + commands = commands.filter(command => !command.isDisabled || !command.isDisabled()); + this._mainWrapperElement.classList.toggle('oe-commandbar-noResult', commands.length === 0); if (commands.length === 0) { return;