to:sync
This commit is contained in:
parent
978bafac7f
commit
a883c64eab
@ -252,6 +252,11 @@ main {
|
|||||||
-webkit-transform: scale(1.375);
|
-webkit-transform: scale(1.375);
|
||||||
transform: scale(1.375);
|
transform: scale(1.375);
|
||||||
|
|
||||||
|
margin: 0 0;
|
||||||
|
padding: 0 0;
|
||||||
|
|
||||||
|
/*display: compact;*/
|
||||||
|
/*width: 2em;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
#testInput {
|
#testInput {
|
||||||
|
@ -176,7 +176,7 @@ define(function (require, exports, module) {
|
|||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
RSizeListener(e) {
|
RSizeListener(e) {
|
||||||
console.log("RSizeListener : ", e);
|
// console.log("RSizeListener : ", e);
|
||||||
let handle = require("./impl/RSizeEventImpl");
|
let handle = require("./impl/RSizeEventImpl");
|
||||||
handle.handle(e);
|
handle.handle(e);
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ define(function (require, exports, module) {
|
|||||||
let curS = utils.GetSelection();
|
let curS = utils.GetSelection();
|
||||||
// console.log("当前内容: ", curP.innerHTML, " 当前选区 :", curS)
|
// console.log("当前内容: ", curP.innerHTML, " 当前选区 :", curS)
|
||||||
//处理前面没有内容,后面还有内容需要拼接到上层的场景
|
//处理前面没有内容,后面还有内容需要拼接到上层的场景
|
||||||
if ((curS.isCollapsed && curS.anchorOffset === 0) || curP.innerHTML === '<br>') {
|
if ((curS.isCollapsed && curS.anchorOffset === 0) || curP.innerHTML === ' ') {
|
||||||
let curNodeRetainHtml = curP.innerHTML
|
let curNodeRetainHtml = curP.innerHTML
|
||||||
//阻止事件传递
|
//阻止事件传递
|
||||||
utils.ProhibitDefaultEvent(event);
|
utils.ProhibitDefaultEvent(event);
|
||||||
@ -83,7 +83,7 @@ define(function (require, exports, module) {
|
|||||||
}
|
}
|
||||||
emptyRowNoList.push(cNo);
|
emptyRowNoList.push(cNo);
|
||||||
//拼接
|
//拼接
|
||||||
if (curNodeRetainHtml !== '<br>') {
|
if (curNodeRetainHtml !== ' ') {
|
||||||
previousSibling.innerHTML = previousSibling.innerHTML + curNodeRetainHtml
|
previousSibling.innerHTML = previousSibling.innerHTML + curNodeRetainHtml
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,13 @@ define(function (require, exports, module) {
|
|||||||
const utils = require('../../common/utils');
|
const utils = require('../../common/utils');
|
||||||
let event = utils.ParseEvent(e);
|
let event = utils.ParseEvent(e);
|
||||||
let curEl = utils.GetEventTarget(event);
|
let curEl = utils.GetEventTarget(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function handleOld(e) {
|
||||||
|
const utils = require('../../common/utils');
|
||||||
|
let event = utils.ParseEvent(e);
|
||||||
|
let curEl = utils.GetEventTarget(event);
|
||||||
|
|
||||||
utils.ProhibitDefaultEvent(event);
|
utils.ProhibitDefaultEvent(event);
|
||||||
let select = utils.GetSelection();
|
let select = utils.GetSelection();
|
||||||
|
@ -26,7 +26,7 @@ define(function (require, exports, module) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function other(mutation) {
|
function other(mutation) {
|
||||||
console.dir(mutation)
|
console.log("other ", mutation)
|
||||||
// console.log("other -> mutation : ", mutation,
|
// console.log("other -> mutation : ", mutation,
|
||||||
// // 观察的变动类型(attributes、characterData或者childList)。
|
// // 观察的变动类型(attributes、characterData或者childList)。
|
||||||
// "\ntype", mutation.type,
|
// "\ntype", mutation.type,
|
||||||
@ -48,12 +48,12 @@ define(function (require, exports, module) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addNewP(mutation) {
|
function addNewP(mutation) {
|
||||||
|
let ctx = require("../../common/ctx");
|
||||||
|
let utils = require("../../common/utils");
|
||||||
//div 下新增p元素
|
//div 下新增p元素
|
||||||
let target = mutation.target;
|
let target = mutation.target;
|
||||||
// target.clone()
|
// target.clone()
|
||||||
if (target.nodeName === "DIV" && mutation.previousSibling !== null) {
|
if (target.nodeName === "DIV" && mutation.previousSibling !== null) {
|
||||||
let utils = require("../../common/utils");
|
|
||||||
let ctx = require("../../common/ctx");
|
|
||||||
let newParagraph = mutation.previousSibling.nextSibling;
|
let newParagraph = mutation.previousSibling.nextSibling;
|
||||||
console.log(
|
console.log(
|
||||||
"addNewP target: ", target,
|
"addNewP target: ", target,
|
||||||
@ -65,46 +65,27 @@ define(function (require, exports, module) {
|
|||||||
)
|
)
|
||||||
if (newParagraph !== undefined && newParagraph !== null) {
|
if (newParagraph !== undefined && newParagraph !== null) {
|
||||||
newParagraph.id = utils.Uuid(ctx.usn, ctx.docType);
|
newParagraph.id = utils.Uuid(ctx.usn, ctx.docType);
|
||||||
newParagraph.setAttribute("data-order", ctx.incrementNumThenReturn());
|
let curNo = ctx.incrementNumThenReturn();
|
||||||
|
newParagraph.setAttribute("data-order", curNo);
|
||||||
// let newParagraph = document.getElementById(targetP.id);
|
|
||||||
//前置 span
|
|
||||||
// let preSpan = newParagraph.querySelector("span[data-flag='span_pre']");
|
|
||||||
// if (preSpan === undefined || preSpan === null) {
|
|
||||||
// preSpan = document.createElement("span");
|
|
||||||
// preSpan.setAttribute("contenteditable", "false")
|
|
||||||
// preSpan.setAttribute("data-flag", "span_pre")
|
|
||||||
//
|
|
||||||
// //额外处理无序和有序列表
|
|
||||||
// let preP = newParagraph.previousElementSibling;
|
|
||||||
// if (preP !== undefined && preP !== null) {
|
|
||||||
// let preSpanTxtOfPreP = preP.querySelector("span[data-flag='span_pre']").textContent;
|
|
||||||
// if (preSpanTxtOfPreP === " • " || preSpanTxtOfPreP === " ◦ " || preSpanTxtOfPreP === " ▪ ") {
|
|
||||||
// preSpan.setAttribute("contenteditable", "true");
|
|
||||||
// preSpan.innerHTML = "<span contenteditable='false'>" + preSpanTxtOfPreP + "</span>";
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //添加到元素首位
|
|
||||||
// newParagraph.insertBefore(preSpan, newParagraph.firstChild);
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// } else {
|
|
||||||
// console.log("newParagraph preSpan exist ", newParagraph, " ", preSpan)
|
|
||||||
// }
|
|
||||||
|
|
||||||
//内置span
|
//内置span
|
||||||
let spanContent = newParagraph.querySelector("span[data-flag='span_content']");
|
let spanContent = newParagraph.querySelector("span[data-flag='span_content']");
|
||||||
if (spanContent === undefined || spanContent === null) {
|
if (spanContent === undefined || spanContent === null) {
|
||||||
spanContent = document.createElement("span");
|
spanContent = document.createElement("span");
|
||||||
// spanContent.append(document.createElement("br"));
|
// spanContent.append(document.createElement("br"));
|
||||||
spanContent.setAttribute("data-flag", "span_content")
|
spanContent.setAttribute("data-flag", "span_content")
|
||||||
spanContent.setAttribute("placeholder", "请输入")
|
if (curNo === 0) { //首行有提示
|
||||||
|
spanContent.setAttribute("placeholder", "请输入")
|
||||||
|
} else {
|
||||||
|
spanContent.setAttribute("placeholder", "请输入")
|
||||||
|
spanContent.innerHTML = " "
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.dir(mutation)
|
||||||
|
|
||||||
newParagraph.appendChild(spanContent);
|
newParagraph.appendChild(spanContent);
|
||||||
} else {
|
} else {
|
||||||
console.log("newParagraph spanContent exist", spanContent);
|
console.log("newParagraph spanContent exist", spanContent);
|
||||||
|
spanContent.innerHTML = " "
|
||||||
spanContent.innerHTML = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.GetSelection().removeAllRanges();
|
utils.GetSelection().removeAllRanges();
|
||||||
@ -116,13 +97,22 @@ define(function (require, exports, module) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//解决(flex 布局 for 无序列表 前面可以输入问题)回车不换行问题
|
//解决(flex 布局 for 无序列表 前面可以输入问题)回车不换行问题
|
||||||
if (target.nodeName === "P" && target.getAttribute("data-order") != null
|
// console.log(" fix ", mutation)
|
||||||
&& mutation.previousSibling !== null && mutation.previousSibling.getAttribute("data-flag") === "span_content") { //
|
if (target.nodeName === "P"
|
||||||
|
&& target.getAttribute("data-order") != null
|
||||||
|
&& mutation.previousSibling !== null
|
||||||
|
&& mutation.previousSibling.getAttribute("data-flag") === "span_content") { //
|
||||||
let utils = require("../../common/utils");
|
let utils = require("../../common/utils");
|
||||||
let flagP = target;
|
let flagP = target;
|
||||||
for (let i = 0; i < mutation.addedNodes.length; i++) {
|
for (let i = 0; i < mutation.addedNodes.length; i++) {
|
||||||
let tmpSpan = mutation.addedNodes[i];
|
let tmpSpan = mutation.addedNodes[i];
|
||||||
let tmpP = document.createElement("p");
|
let tmpP = document.createElement("p");
|
||||||
|
let curNo = ctx.getCurRowNo();
|
||||||
|
if (curNo === 0) { //首行有提示
|
||||||
|
tmpSpan.setAttribute("placeholder", "请输入")
|
||||||
|
} else {
|
||||||
|
tmpSpan.textContent = "\n"
|
||||||
|
}
|
||||||
tmpP.appendChild(tmpSpan)
|
tmpP.appendChild(tmpSpan)
|
||||||
utils.InsertAfter(flagP, tmpP);
|
utils.InsertAfter(flagP, tmpP);
|
||||||
flagP = tmpP;
|
flagP = tmpP;
|
||||||
@ -130,33 +120,6 @@ define(function (require, exports, module) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//删除 for 无序列表 删除样式恢复正常行
|
|
||||||
// if (mutation.removedNodes.length === 0
|
|
||||||
// && mutation.addedNodes.length === 1
|
|
||||||
// && target.nodeName === "P" && target.getAttribute("data-order") != null
|
|
||||||
// // && target.childNodes
|
|
||||||
// && mutation.addedNodes[0].nodeName === "BR"
|
|
||||||
// ) {
|
|
||||||
// console.log(
|
|
||||||
// "删除 br target: ", target,
|
|
||||||
// "\nmutation:", mutation,
|
|
||||||
// "\ntarget.childNodes:", target.childNodes,
|
|
||||||
// "\naddedNodes:", mutation.addedNodes,
|
|
||||||
// "\nremovedNodes:", mutation.removedNodes,
|
|
||||||
// "\nnodeType: ", mutation.addedNodes[0].nodeType,
|
|
||||||
// "\nnodeName: ", mutation.addedNodes[0].nodeName,
|
|
||||||
// "\ndata: ", mutation.addedNodes[0].value
|
|
||||||
// )
|
|
||||||
// console.log("捕捉 ‘删除样式恢复正常行’ 成功")
|
|
||||||
//
|
|
||||||
// let spanContent = document.createElement("span");
|
|
||||||
// spanContent.setAttribute("data-flag", "span_content")
|
|
||||||
// spanContent.innerHTML = "<br>";
|
|
||||||
// target.innerHTML = null;
|
|
||||||
// target.append(spanContent);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
other(mutation);
|
other(mutation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,43 +193,6 @@ define(function (require, exports, module) {
|
|||||||
let curSpanContent = curP.querySelector("span[data-flag='span_content']")
|
let curSpanContent = curP.querySelector("span[data-flag='span_content']")
|
||||||
// console.log("curSpanContent: ", curSpanContent)
|
// console.log("curSpanContent: ", curSpanContent)
|
||||||
|
|
||||||
//无序列表
|
|
||||||
// if (curSpanContent.innerHTML.startsWith("- ") || curSpanContent.innerHTML.startsWith("- ")) {
|
|
||||||
// let curPreSpan = curP.querySelector("span[data-flag='span_pre']");
|
|
||||||
// let curPreSpanTxt = utils.GetText(curPreSpan);
|
|
||||||
// if (curPreSpanTxt === " • " || curPreSpanTxt === " ◦ " || curPreSpanTxt === " ▪ ") {
|
|
||||||
// return;
|
|
||||||
// } else {
|
|
||||||
// let previousSiblingP = curP.previousElementSibling;
|
|
||||||
// let preSpanTxtOfPreP = null
|
|
||||||
// if (previousSiblingP != null) {
|
|
||||||
// let tmpPre = previousSiblingP.querySelector("span[data-flag='span_pre']");
|
|
||||||
// preSpanTxtOfPreP = utils.GetText(tmpPre);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //上一级是否也是无序列表。 如果是则 后移
|
|
||||||
// if (preSpanTxtOfPreP != null && (preSpanTxtOfPreP === " • " || preSpanTxtOfPreP === " ◦ " || preSpanTxtOfPreP === " ▪ ")) {
|
|
||||||
// if (preSpanTxtOfPreP === " • ") {
|
|
||||||
// curPreSpan.setAttribute("contenteditable", "true");
|
|
||||||
// curPreSpan.innerHTML = "<span contenteditable='false'>" + " ◦ " + "</span>"
|
|
||||||
// } else if (preSpanTxtOfPreP === " ◦ ") {
|
|
||||||
// curPreSpan.setAttribute("contenteditable", "true");
|
|
||||||
// curPreSpan.innerHTML = "<span contenteditable='false'>" + " ▪ " + "</span>"
|
|
||||||
// } else {
|
|
||||||
// console.log("不支持继续下转")
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// curPreSpan.innerHTML = "<span>" + " • " + "</span>"
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// curSpanContent.textContent = curSpanContent.textContent.substring(2, curSpanContent.textContent.length);
|
|
||||||
//
|
|
||||||
// //光标定位
|
|
||||||
// utils.GetSelection().removeAllRanges();
|
|
||||||
// utils.GetSelection().setPosition(curSpanContent, 0);
|
|
||||||
// curSpanContent.focus();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
} else {
|
} else {
|
||||||
other(mutation);
|
other(mutation);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user