to:sync
This commit is contained in:
parent
795da149a7
commit
95e072ab18
@ -20,6 +20,9 @@ define(function (require, exports, module) {
|
|||||||
for (let i = 0; i < curS.rangeCount; i++) {
|
for (let i = 0; i < curS.rangeCount; i++) {
|
||||||
let curRange = curS.getRangeAt(i);
|
let curRange = curS.getRangeAt(i);
|
||||||
let curCommonEle = curRange.commonAncestorContainer;
|
let curCommonEle = curRange.commonAncestorContainer;
|
||||||
|
let curStartContainerEle = curRange.startContainer;
|
||||||
|
let curEndContainerEle = curRange.endContainer;
|
||||||
|
let taskMap = new Map;
|
||||||
let start = curRange.startOffset;
|
let start = curRange.startOffset;
|
||||||
let end = curRange.endOffset;
|
let end = curRange.endOffset;
|
||||||
if (start > end) {
|
if (start > end) {
|
||||||
@ -27,36 +30,37 @@ define(function (require, exports, module) {
|
|||||||
start = end;
|
start = end;
|
||||||
end = tmpS;
|
end = tmpS;
|
||||||
}
|
}
|
||||||
if (start === end) {
|
|
||||||
|
let tmpStart = getSpanContent(curStartContainerEle);
|
||||||
|
let tmpEnd = getSpanContent(curEndContainerEle);
|
||||||
|
if (tmpStart.getAttribute("id") === tmpEnd.getAttribute("id")) {
|
||||||
|
taskMap.set(tmpStart.getAttribute("id"), tmpStart)
|
||||||
|
} else {
|
||||||
|
let tmp = tmpStart;
|
||||||
|
if (parseInt(tmpStart.getAttribute("data-order")) > parseInt(tmpEnd.getAttribute("data-order"))) {
|
||||||
|
tmpStart = tmpEnd;
|
||||||
|
tmpEnd = tmp;
|
||||||
|
}
|
||||||
|
taskMap.set(tmpStart.getAttribute("id"), tmpStart)
|
||||||
|
while (true) {
|
||||||
|
let nextTask = tmpStart.nextSibling;
|
||||||
|
taskMap.set(nextTask.getAttribute("id"), nextTask);
|
||||||
|
if (nextTask.getAttribute("id") === tmpEnd.getAttribute("id")) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (taskMap.size === 1 && start === end) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// //一个元素节点,例如 <p> 和 <div>。
|
for (let [key, curSpanContent] of taskMap) {
|
||||||
// let curComIsSpan = curCommonEle.nodeType === 1 && curCommonEle.nodeName === "SPAN";
|
console.log("curSpanContent : ", curSpanContent, "\n", curCommonEle, "\nsize:", taskMap.size);
|
||||||
// let curComParentIsP = curCommonEle.parentNode.nodeType === 1 && curCommonEle.parentNode.nodeName === "P";
|
console.dir(taskMap)
|
||||||
// let curComParentIsDiv = curCommonEle.parentNode.nodeType === 1 && curCommonEle.parentNode.nodeName === "DIV";
|
console.dir(curS)
|
||||||
// let curComParentIsSpan = curCommonEle.parentNode.nodeType === 1 && (curCommonEle.parentNode.nodeName === 'SPAN"' || curCommonEle.parentNode.nodeName === 'SPAN');
|
console.dir(curRange)
|
||||||
// console.log(" 当前选区信息 : ", curRange,
|
|
||||||
// "\ncurCommonEle: ", curCommonEle,
|
|
||||||
// "\ncurCommonEleParent: ", curCommonEle.parentNode, curCommonEle.parentNode.nodeType, curCommonEle.parentNode.nodeName,
|
|
||||||
// "\ncurCommonEleParentParent: ", curCommonEle.parentNode.parentNode, curCommonEle.parentNode.parentNode.nodeType, curCommonEle.parentNode.parentNode.nodeName,
|
|
||||||
//
|
|
||||||
// "\ncurComParentIsSpan: ", curComParentIsSpan,
|
|
||||||
// "\ncurComParentIsP : ", curComParentIsP,
|
|
||||||
// "\ncurComParentIsDiv", curComParentIsDiv,
|
|
||||||
// "\ncurComIsSpan", curComIsSpan,
|
|
||||||
//
|
|
||||||
// "\nstyleK: ", styleK,
|
|
||||||
// "\nstyleV: ", styleV,
|
|
||||||
// "\ntart: ", start,
|
|
||||||
// "\nend: ", end);
|
|
||||||
|
|
||||||
let curSpanContent = curCommonEle;
|
if (curSpanContent.childNodes === undefined || curSpanContent.childNodes === null || curSpanContent.childNodes.length <= 0) {
|
||||||
if (curSpanContent.nodeName !== "SPAN" || curSpanContent.getAttribute("data-flag") !== "span_content") {
|
|
||||||
curSpanContent = curSpanContent.parentElement.closest("span[data-flag='span_content']");
|
|
||||||
}
|
|
||||||
console.log("curSpanContent : ", curSpanContent, curCommonEle);
|
|
||||||
if (curSpanContent.childNodes.length <= 0) {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
let firstItem = curSpanContent.childNodes[0];
|
let firstItem = curSpanContent.childNodes[0];
|
||||||
@ -81,7 +85,8 @@ define(function (require, exports, module) {
|
|||||||
|
|
||||||
curSpanContent.innerHTML = copySpan.innerHTML;
|
curSpanContent.innerHTML = copySpan.innerHTML;
|
||||||
|
|
||||||
//光标保持
|
//光标保持. for 单行
|
||||||
|
if (taskMap.size === 1) {
|
||||||
let s = window.getSelection();
|
let s = window.getSelection();
|
||||||
if (s.rangeCount > 0) s.removeAllRanges();
|
if (s.rangeCount > 0) s.removeAllRanges();
|
||||||
let newR = document.createRange();
|
let newR = document.createRange();
|
||||||
@ -93,6 +98,7 @@ define(function (require, exports, module) {
|
|||||||
newR.setEnd(tmpP, end);
|
newR.setEnd(tmpP, end);
|
||||||
//区域 添加 到选区
|
//区域 添加 到选区
|
||||||
s.addRange(newR);
|
s.addRange(newR);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
let total = 0, effectNum = 0;
|
let total = 0, effectNum = 0;
|
||||||
for (let j = 0; j < curSpanContent.childNodes.length; j++) {
|
for (let j = 0; j < curSpanContent.childNodes.length; j++) {
|
||||||
@ -120,6 +126,7 @@ define(function (require, exports, module) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function removeSpanStyleKV(span, styleK, styleV) {
|
function removeSpanStyleKV(span, styleK, styleV) {
|
||||||
let kList = styleK.toString().split(",");
|
let kList = styleK.toString().split(",");
|
||||||
@ -152,6 +159,15 @@ define(function (require, exports, module) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getSpanContent(item) {
|
||||||
|
let tmp = item;
|
||||||
|
if (item.nodeName !== "SPAN" || item.getAttribute("data-flag") !== "span_content") {
|
||||||
|
tmp = item.parentElement.closest("span[data-flag='span_content']");
|
||||||
|
}
|
||||||
|
return tmp
|
||||||
|
}
|
||||||
|
|
||||||
//导出
|
//导出
|
||||||
exports.handle = handle;
|
exports.handle = handle;
|
||||||
});
|
});
|
Loading…
x
Reference in New Issue
Block a user