From 25849e918651eba080dac3af4e4fcdc8f1280241 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Thu, 25 Jan 2018 14:25:35 +0100 Subject: [PATCH] [FIX] web_editor: properly allow formatting text (normal/header 1/...) Sometimes the formatting buttons had no effect or formatted more than they should (like a whole column when triple clicking on a paragraph only). This was because of the `listBetween` function implementation. This is supposed to return all the nodes between one element and another one... but the logic is wrong without saying from which *point* to start and which *point* to end. For example, when asking the list between an element and its parent, the result is very wrong as there is no way to go from the beginning of an element to the beginning of its parent using the `walkPoint` function as the `listBetween` function is doing. Ideally, the function should be entirely fixed but this can be tricky. For now, the function is just extended to allow to specify points instead of nodes, and those are used by the `formatBlock` function to solve the current problem. --- addons/web_editor/static/src/js/summernote.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/addons/web_editor/static/src/js/summernote.js b/addons/web_editor/static/src/js/summernote.js index 1f2176f3751..cdf4329c0b9 100644 --- a/addons/web_editor/static/src/js/summernote.js +++ b/addons/web_editor/static/src/js/summernote.js @@ -703,10 +703,16 @@ dom.isRemovableEmptyNode = function (node) { dom.isForbiddenNode = function (node) { return node.tagName === "BR" || $(node).is(".fa, img"); }; -dom.listBetween = function (sc, ec) { +/** + * @todo 'so' and 'eo' were added as a bugfix and are not given everytime. They + * however should be as the function may be wrong without them (for example, + * when asking the list between an element and its parent, as there is no path + * from the beginning of the former to the beginning of the later). + */ +dom.listBetween = function (sc, ec, so, eo) { var nodes = []; var ancestor = dom.commonAncestor(sc, ec); - dom.walkPoint({'node': sc, 'offset': 0}, {'node': ec, 'offset': 0}, function (point) { + dom.walkPoint({'node': sc, 'offset': so || 0}, {'node': ec, 'offset': eo || 0}, function (point) { if (ancestor !== point.node || ancestor === sc || ancestor === ec) { nodes.push(point.node); } @@ -1923,7 +1929,7 @@ $.summernote.pluginEvents.formatBlock = function (event, editor, layoutInfo, sTa } // fix by odoo because if you select a style in a li with no p tag all the ul is wrapped by the style tag - var nodes = dom.listBetween(r.sc, r.ec); + var nodes = dom.listBetween(r.sc, r.ec, r.so, r.eo); for (var i=0; i