From 8acd1c40fe8cbbef760c0ad4321f0977d17ebe66 Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Tue, 6 Oct 2015 16:40:58 +0200 Subject: [PATCH] [FIX] web_editor: alt+tab in table and tab on collapse When using the tab key on non text node range, it could fail in some given case. Also when removing the last element of the table row, a correction was done in d33086c03fc but if there was no element before the table (eg. the editor is empty) an error could occur. --- addons/web_editor/static/src/js/summernote.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/addons/web_editor/static/src/js/summernote.js b/addons/web_editor/static/src/js/summernote.js index 19f559070d7..354deb19902 100644 --- a/addons/web_editor/static/src/js/summernote.js +++ b/addons/web_editor/static/src/js/summernote.js @@ -1039,7 +1039,12 @@ $.summernote.pluginEvents.tab = function (event, editor, layoutInfo, outdent) { } } else { if (!outdent){ - var next = r.sc.splitText(r.so); + if(dom.isText(r.sc)) { + var next = r.sc.splitText(r.so); + } else { + var next = document.createTextNode('') + $(r.sc.childNodes[r.so]).before(next); + } editor.typing.insertTab($editable, r, options.tabsize); r = range.create(next, 0, next, 0); r = dom.merge(r.sc.parentNode, r.sc, r.so, r.ec, r.eo, null, true); @@ -1434,7 +1439,7 @@ $.summernote.pluginEvents.backspace = function (event, editor, layoutInfo) { if (prevTr) { node = (dom.lastElementChild(prevTr).lastChild && dom.lastElementChild(prevTr).lastChild.tagName ? dom.lastElementChild(prevTr).lastChild.previousSibling : dom.lastElementChild(prevTr).lastChild) || dom.lastElementChild(prevTr); } else { - node = dom.lastChild(dom.hasContentBefore(dom.ancestorHavePreviousSibling(tr))); + node = dom.lastChild(dom.hasContentBefore(dom.ancestorHavePreviousSibling(tr)) || $editable.get(0)); } $(tr).empty(); if(!$(tr).closest('table').has('td, th').length) {