diff --git a/addons/web_editor/static/src/js/editor/rte.summernote.js b/addons/web_editor/static/src/js/editor/rte.summernote.js index 0470435075b..2c9e06d89be 100644 --- a/addons/web_editor/static/src/js/editor/rte.summernote.js +++ b/addons/web_editor/static/src/js/editor/rte.summernote.js @@ -25,6 +25,37 @@ var range = $.summernote.core.range; var eventHandler = $.summernote.eventHandler; var renderer = $.summernote.renderer; +// Summernote uses execCommand and, worth, obsolete queryCommandState function +// to customize the edited content. Here we try to hack the function to solve +// some problems by making the DOM and style easier to understand for the +// base function for the duration of their executions. This won't obviously +// solves all problems but this is an improvement while waiting for the new +// Odoo editor coming in future versions. +function protectCommand(callback) { + return function () { + var rng = range.create(); + var $sc = (rng && rng.sc) ? $(rng.sc).parents(':o_editable').last() : $(); + var $ec = (rng && rng.ec) ? $(rng.ec).parents(':o_editable').last() : $(); + $sc.addClass('o_we_command_protector'); + $ec.addClass('o_we_command_protector'); + var restore = function () { + $sc.removeClass('o_we_command_protector'); + $ec.removeClass('o_we_command_protector'); + }; + var result; + try { + result = callback.apply(this, arguments); + } catch (err) { + restore(); + throw err; + } + restore(); + return result; + }; +} +document.execCommand = protectCommand(document.execCommand); +document.queryCommandState = protectCommand(document.queryCommandState); + var tplButton = renderer.getTemplate().button; var tplIconButton = renderer.getTemplate().iconButton; var tplDropdown = renderer.getTemplate().dropdown; diff --git a/addons/web_editor/static/src/scss/wysiwyg.scss b/addons/web_editor/static/src/scss/wysiwyg.scss index 53dbf927cfa..7e31a56d58b 100644 --- a/addons/web_editor/static/src/scss/wysiwyg.scss +++ b/addons/web_editor/static/src/scss/wysiwyg.scss @@ -7,6 +7,17 @@ $o-we-zindex: $o-we-overlay-zindex + 1 !default; @include print-variable('o-we-toolbar-height', $o-we-toolbar-height); } +.o_we_command_protector { + font-weight: 400 !important; + + b, strong { + font-weight: 700 !important; + } + * { + font-weight: inherit !important; + } +} + // EDITOR TOP BAR AND POPOVER .note-popover .popover { max-width: 350px;