From 39e27fe391c5c186248aa40363eff3db51aa1e36 Mon Sep 17 00:00:00 2001 From: shaoyongjun Date: Wed, 6 Nov 2024 13:17:49 +0800 Subject: [PATCH] =?UTF-8?q?add:=E5=85=89=E6=A0=87=E4=BF=9D=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/js/event/impl/ApplyStyleEventImpl.js | 23 +++++++-------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/static/js/event/impl/ApplyStyleEventImpl.js b/static/js/event/impl/ApplyStyleEventImpl.js index 7011ce3..20881a7 100644 --- a/static/js/event/impl/ApplyStyleEventImpl.js +++ b/static/js/event/impl/ApplyStyleEventImpl.js @@ -8,6 +8,7 @@ define(function (require, exports, module) { let utils = require("../../common/utils"); let curS = utils.GetSelection(); let curRange = curS.getRangeAt(0); //只考虑一个选区场景 + let copyRange = curRange.cloneRange(); let curNode = utils.GetEventTarget(event); //只处理选择的是一个范围。 if (curS.type !== "Range") { @@ -129,21 +130,6 @@ define(function (require, exports, module) { } curSpanContent.innerHTML = copySpan.innerHTML; - - //光标保持. for 单行 - if (taskMap.size === 1) { - let s = window.getSelection(); - if (s.rangeCount > 0) s.removeAllRanges(); - let newR = document.createRange(); - //重新获取元素 - let tmpP = curSpanContent; - let childrenSize = tmpP.childNodes.length; - console.log("debug007: ", tmpP, start, end, childrenSize) - newR.setStart(tmpP, start); - newR.setEnd(tmpP, end); - //区域 添加 到选区 - s.addRange(newR); - } } else { let total = 0, effectNum = 0; for (let j = 0; j < curSpanContent.childNodes.length; j++) { @@ -170,6 +156,13 @@ define(function (require, exports, module) { } } } + + //光标保持 + curS.removeAllRanges(); + let newR = document.createRange(); + newR.setStart(copyRange.startContainer,start); + newR.setEnd(copyRange.endContainer,end); + curS.addRange(newR); } function removeSpanStyleKV(span, styleK, styleV) {