Skip to content

Commit

Permalink
2.38.10
Browse files Browse the repository at this point in the history
  • Loading branch information
JiHong88 committed May 11, 2021
2 parents 878f55f + 2f1c895 commit 31f8dba
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 62 deletions.
4 changes: 2 additions & 2 deletions dist/suneditor.min.js

Large diffs are not rendered by default.

42 changes: 0 additions & 42 deletions sample/html/out/document-editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -1336,47 +1336,6 @@ <h5>Parameters:</h5>
<dl class="details"></dl>


<h4 class="name" id="isEdgeFormat"><span class="type-signature"></span>isEdgeFormat<span class="signature">(container, offset, dir)</span><span
class="type-signature"> &rarr; {Boolean}</span></h4>
<div class="description">
Check if the container and offset values are the edges of the format tag
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>container</code></td>
<td class="type">
<span class="param-type">Node</span>
</td>
<td class="description last">The node of the selection object. (range.startContainer..)</td>
</tr>
<tr>
<td class="name"><code>offset</code></td>
<td class="type">
<span class="param-type">Number</span>
</td>
<td class="description last">The offset of the selection object. (core.getRange().startOffset...)</td>
</tr>
<tr>
<td class="name"><code>dir</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">Select check point - "front": Front edge, "end": End edge, undefined: Both edge.</td>
</tr>
</tbody>
</table>
<dl class="details"></dl>


<h4 class="name" id="showLoading"><span class="type-signature"></span>showLoading<span
class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
Expand Down Expand Up @@ -2337,7 +2296,6 @@ <h3>core</h3>
<li><a href="document-editor.html#getSelectedElements">getSelectedElements</a></li>
<li><a href="document-editor.html#getSelectedElementsAndComponents">getSelectedElementsAndComponents</a></li>
<li><a href="document-editor.html#isEdgePoint">isEdgePoint</a></li>
<li><a href="document-editor.html#isEdgeFormat">isEdgeFormat</a></li>
<li><a href="document-editor.html#showLoading">showLoading</a></li>
<li><a href="document-editor.html#closeLoading">closeLoading</a></li>
<li><a href="document-editor.html#appendFormatTag">appendFormatTag</a></li>
Expand Down
9 changes: 0 additions & 9 deletions src/lib/core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,15 +352,6 @@ interface Core {
*/
isEdgePoint(container: Node, offset: number, dir?: 'front' | 'end'): boolean;

/**
* @description Check if the container and offset values are the edges of the format tag
* @param container The container property of the selection object.
* @param offset The offset property of the selection object.
* @param dir Select check point - "front": Front edge, "end": End edge, undefined: Both edge.
* @returns
*/
isEdgeFormat(container: Node, offset: number, dir: 'front' | 'end'): boolean;

/**
* @description Show loading box
*/
Expand Down
33 changes: 24 additions & 9 deletions src/lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1351,21 +1351,23 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re
* @param {Node} container The node of the selection object. (range.startContainer..)
* @param {Number} offset The offset of the selection object. (core.getRange().startOffset...)
* @param {String} dir Select check point - "front": Front edge, "end": End edge, undefined: Both edge.
* @returns {Boolean}
* @returns {Array|null}
* @private
*/
isEdgeFormat: function (node, offset, dir) {
_isEdgeFormat: function (node, offset, dir) {
if (!this.isEdgePoint(node, offset, dir)) return false;

let result = true;
const result = [];
dir = dir === 'front' ? 'previousSibling' : 'nextSibling';
while (node && !util.isFormatElement(node) && !util.isWysiwygDiv(node)) {
if (node.nodeType === 3 && (!node[dir] || (util.isBreak(node[dir]) && !node[dir][dir]))) {
if (!node[dir] || (util.isBreak(node[dir]) && !node[dir][dir])) {
if (node.nodeType === 1) result.push(node.cloneNode(false));
node = node.parentNode;
} else {
result = false;
node = null;
return null;
}
}

return result;
},

Expand Down Expand Up @@ -6417,10 +6419,23 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re
}

if (!shift) {
if (core.isEdgeFormat(range.endContainer, range.endOffset, 'end') || /^HR$/i.test(formatEl.nodeName)) {
const formatInners = core._isEdgeFormat(range.endContainer, range.endOffset, 'end');
if ((formatInners && /^H[1-6]$/i.test(formatEl.nodeName)) || /^HR$/i.test(formatEl.nodeName)) {
e.preventDefault();
const newFormat = core.appendFormatTag(formatEl, /^H[1-6r]$/i.test(formatEl.nodeName) ? options.defaultTag : formatEl.cloneNode(true));
core.setRange(newFormat, 1, newFormat, 1);
let temp = null;
const newFormat = core.appendFormatTag(formatEl, options.defaultTag);

if (formatInners && formatInners.length > 0) {
temp = formatInners.pop();
const innerNode = temp;
while(formatInners.length > 0) {
temp = temp.appendChild(formatInners.pop());
}
newFormat.appendChild(innerNode);
}

temp = !temp ? newFormat.firstChild : temp.appendChild(newFormat.firstChild);
core.setRange(temp, 0, temp, 0);
break;
}

Expand Down

0 comments on commit 31f8dba

Please sign in to comment.