From f93e03c4c7c7f08f73f0c7cfbb388c4ce7dfc3d3 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 20 Jan 2016 12:07:16 +0100 Subject: [PATCH] [FIX] web_editor: can indent table cell (with button and tab) issue: the user select some line and keypress tab without indent, and the button indent doesn't work in table cell --- addons/web_editor/static/src/js/summernote.js | 37 ++++++++++--------- addons/web_editor/static/src/js/tour.rte.js | 2 +- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/addons/web_editor/static/src/js/summernote.js b/addons/web_editor/static/src/js/summernote.js index 6ed7be2039f..e31faaab601 100644 --- a/addons/web_editor/static/src/js/summernote.js +++ b/addons/web_editor/static/src/js/summernote.js @@ -558,13 +558,15 @@ dom.removeBetween = function (sc, so, ec, eo, towrite) { }; }; dom.indent = function (node) { - var margin = parseFloat(node.style.marginLeft || 0)+1.5; - node.style.marginLeft = margin + "em"; + var style = dom.isCell(node) ? 'paddingLeft' : 'marginLeft'; + var margin = parseFloat(node.style[style] || 0)+1.5; + node.style[style] = margin + "em"; return margin; }; dom.outdent = function (node) { - var margin = parseFloat(node.style.marginLeft || 0)-1.5; - node.style.marginLeft = margin > 0 ? margin + "em" : ""; + var style = dom.isCell(node) ? 'paddingLeft' : 'marginLeft'; + var margin = parseFloat(node.style[style] || 0)-1.5; + node.style[style] = margin > 0 ? margin + "em" : ""; return margin; }; dom.scrollIntoViewIfNeeded = function (node) { @@ -950,9 +952,10 @@ $.summernote.pluginEvents.tab = function (event, editor, layoutInfo, outdent) { $editable.data('NoteHistory').recordUndo($editable, 'tab'); var r = range.create(); var outdent = outdent || false; + event.preventDefault(); - if (r && r.isCollapsed()) { - if (r.isOnCell() && r.isOnCellFirst()) { + if (r && (dom.ancestor(r.sc, dom.isCell) || dom.ancestor(r.ec, dom.isCell))) { + if (r.isCollapsed() && r.isOnCell() && r.isOnCellFirst()) { var td = dom.ancestor(r.sc, dom.isCell); if (!outdent && !dom.nextElementSibling(td) && !dom.nextElementSibling(td.parentNode)) { var last = dom.lastChild(td); @@ -963,10 +966,10 @@ $.summernote.pluginEvents.tab = function (event, editor, layoutInfo, outdent) { } else { editor.table.tab(r, outdent); } - event.preventDefault(); - return false; + } else { + $.summernote.pluginEvents.indent(event, editor, layoutInfo, outdent); } - + } else if (r && r.isCollapsed()) { if (!r.sc.textContent.slice(0,r.so).match(/\S/) && r.isOnList()) { if (outdent) { $.summernote.pluginEvents.outdent(event, editor, layoutInfo); @@ -993,11 +996,8 @@ $.summernote.pluginEvents.tab = function (event, editor, layoutInfo, outdent) { next.textContent = next.textContent.replace(/^(\u00A0)+/g, ''); range.create(r.sc, r.sc.textContent.length, r.sc, r.sc.textContent.length).select(); } - event.preventDefault(); - return false; } } - event.preventDefault(); return false; }; $.summernote.pluginEvents.untab = function (event, editor, layoutInfo) { @@ -1724,7 +1724,7 @@ $.summernote.pluginEvents.indent = function (event, editor, layoutInfo, outdent) dom.merge(parent, start, 0, end, 1, null, true); } function indentOther (p, start, end) { - if (p === start || $.contains(p, start)) { + if (p === start || $.contains(p, start) || $.contains(start, p)) { flag = true; } if (flag) { @@ -1734,7 +1734,7 @@ $.summernote.pluginEvents.indent = function (event, editor, layoutInfo, outdent) dom.indent(p); } } - if (p === end || $.contains(p, end)) { + if (p === end || $.contains(p, end) || $.contains(end, p)) { flag = false; } } @@ -1743,15 +1743,18 @@ $.summernote.pluginEvents.indent = function (event, editor, layoutInfo, outdent) var $dom = $(ancestor); if (!dom.isList(ancestor)) { - $dom = $(ancestor).children(); + $dom = $(dom.node(ancestor)).children(); } if (!$dom.length) { - $dom = $(dom.ancestor(r.sc, dom.isList)); + $dom = $(dom.ancestor(r.sc, dom.isList) || dom.ancestor(r.sc, dom.isCell)); if (!$dom.length) { $dom = $(r.sc).closest(options.styleTags.join(',')); } } + // if select tr, take the first td + $dom = $dom.map(function () { return this.tagName === "TR" ? dom.firstElementChild(this) : this; }); + $dom.each(function () { if (flag || $.contains(this, r.sc)) { if (dom.isList(this)) { @@ -1760,7 +1763,7 @@ $.summernote.pluginEvents.indent = function (event, editor, layoutInfo, outdent) } else { indentUL(this, r.sc, r.ec); } - } else if (isFormatNode(this)) { + } else if (isFormatNode(this) || dom.ancestor(this, dom.isCell)) { indentOther(this, r.sc, r.ec); } } diff --git a/addons/web_editor/static/src/js/tour.rte.js b/addons/web_editor/static/src/js/tour.rte.js index 5205e60eef8..8c3c494a73f 100644 --- a/addons/web_editor/static/src/js/tour.rte.js +++ b/addons/web_editor/static/src/js/tour.rte.js @@ -20,7 +20,7 @@ Tour.register({ id: 'rte', name: "Test RTE", mode: 'test', - path: '/web_editor/field/html?callback=FieldTextHtml_0&enable_editor=1&datarecord=%7B%7D', + path: '/web_editor/field/html?debug&callback=FieldTextHtml_0&enable_editor=1&datarecord=%7B%7D', steps: [ { title: "Change html for this test",