From bae73ca9a742b9d524374ae013cfeeb37c020a8f Mon Sep 17 00:00:00 2001 From: JiHong88 <0125ses@hanmail.net> Date: Fri, 3 Jan 2025 20:22:38 +0900 Subject: [PATCH] Fix: core._resetRangeToTextNode #1471 #1472 #1473 --- src/lib/core.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/lib/core.js b/src/lib/core.js index 0ff02d3c..0eab5e8e 100755 --- a/src/lib/core.js +++ b/src/lib/core.js @@ -1270,6 +1270,7 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re const range = this.getRange(); if (this._selectionVoid(range)) return false; + const collapsed = range.collapsed; let startCon = range.startContainer; let startOff = range.startOffset; let endCon = range.endContainer; @@ -1294,7 +1295,7 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re while (endCon && endCon.nodeType === 1 && endCon.lastChild) { endCon = endCon.lastChild; } - endOff = endCon.textContent.length; + endOff = collapsed ? 0 : endCon.textContent.length; } // startContainer @@ -1477,7 +1478,7 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re * @param {String|undefined} dir Select check point - Both edge, Front edge or End edge. ("start": Front edge, "end": End edge, undefined: Both edge) * @returns {Boolean} */ - isEdgePoint: function (container, offset, dir) { + isEdgePoint: function (container, offset, dir) { if (container.nodeType === 1 && !container.textContent.length) return true; return (dir !== 'end' && offset === 0) || ((!dir || dir !== 'start') && !container.nodeValue && offset === 1) || ((!dir || dir === 'end') && !!container.nodeValue && offset === container.nodeValue.length); }, @@ -7208,12 +7209,12 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re e.preventDefault(); e.stopPropagation(); break; - } - - if (!selectRange && core._isEdgeFormat(range.endContainer, range.endOffset, 'end') && !formatEl.nextSibling) { - e.preventDefault(); - e.stopPropagation(); - return; + } + + if (!selectRange && core._isEdgeFormat(range.endContainer, range.endOffset, 'end') && !formatEl.nextSibling) { + e.preventDefault(); + e.stopPropagation(); + return; } // tag[contenteditable="false"]