[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
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user