[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
d33086c03f but if there was no element before the table (eg. the editor
is empty) an error could occur.
This commit is contained in:
Nicolas Lempereur
2015-10-09 08:43:49 +02:00
parent 8c3b4b80c6
commit 8acd1c40fe
@@ -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) {