add:输入分解

This commit is contained in:
shaoyongjun 2024-11-07 14:16:50 +08:00
parent 64f268ef8f
commit 70eff9141b
6 changed files with 72 additions and 15 deletions

View File

@ -47,6 +47,8 @@ define(function (require, exports, module) {
//最近一次操作
this.latestOpDoc = null;
//Compositionstart
this.Compositionstart = false
//初始化
}
@ -66,7 +68,7 @@ define(function (require, exports, module) {
return this.rowNo++;
}
getCurRowNo(){
getCurRowNo() {
return this.rowNo
}

View File

@ -154,6 +154,17 @@ define(function (require, exports, module) {
//兼容IE
targetElement.fireEvent('focus');
}
},
/**
* 获取元素
* @param element
* @returns {string|string|*}
* @constructor
*/
GetText(element) {
//textContent 性能 准确性更好
return element.textContent || element.innerText;
}
}

View File

@ -48,6 +48,11 @@ define(function (require, exports, module) {
characterDataOldValue: true
});
//中文输入
document.getElementById("yxl_note").addEventListener('compositionstart',
this.CompositionstartListener);
document.getElementById("yxl_note").addEventListener('compositionend',
this.CompositionendListener);
//这里监听鼠标按下事件
document.getElementById("_style_utils").addEventListener("mousedown", this.Mousedown, false);
@ -125,9 +130,8 @@ define(function (require, exports, module) {
* @constructor
*/
CompositionstartListener(e) {
const utils = require('../common/utils');
const event = utils.ParseEvent(e);
// window.myEdit.biz.compositionstartHandle(event);
const ctx = require('../common/ctx');
ctx.Compositionstart = true
}
/**
@ -136,10 +140,8 @@ define(function (require, exports, module) {
* @constructor
*/
CompositionendListener(e) {
const utils = require('../common/utils');
const event = utils.ParseEvent(e);
console.log("Compositionend : ", event)
// window.myEdit.biz.compositionendHandle(event);
const ctx = require('../common/ctx');
ctx.Compositionstart = false
}
/**

View File

@ -27,6 +27,10 @@ define(function (require, exports, module) {
//回车事件,禁止处理。防止生成 div
if (keyCode === 13) {
// utils.ProhibitDefaultEvent(event);
// const enterHandle = require('./EnterEventImpl')
// enterHandle.handle(e);
// return;
}
//在鼠标按下的时候删除,体验更好

View File

@ -20,7 +20,7 @@ define(function (require, exports, module) {
if (keyCombination && keyCode === 67) {
// 阻止默认事件
// utils.ProhibitDefaultEvent(event);
// console.log('触发ctrl + c 事件', e.target)
console.log('触发ctrl + c 事件', e.target)
}
//撤销

View File

@ -105,18 +105,56 @@ define(function (require, exports, module) {
let target = mutation.target;
if (target.nodeType === 3 && target.nodeName === "#text") {
// console.log(
// "target: ", target,
// "updateText target: ", target,
// "\nnodeType: ", target.nodeType,
// "\nnodeName: ", target.nodeName,
// "\ndata: ", target.value,
// "\nparentNode: ", target.parentNode,
// "\nparentNode_parentNode: ", target.parentNode.parentNode,
// "\nparentNode_parentNode: ", target.parentNode?.parentNode,
// )
// let curSpan = target.parentNode;
// let curP = target.parentNode.parentNode;
let grandfatherElement = target.parentNode?.parentElement;
if (grandfatherElement != null && grandfatherElement.getAttribute("data-flag") === "span_content") {
let utils = require("../../common/utils");
let ctx = require("../../common/ctx");
//正在输入中文直接忽略
if (ctx.Compositionstart) {
return;
}
let select = utils.GetSelection();
let selectRange = select.getRangeAt(0);
if (select.isCollapsed) { //输入场景
let tmpSpan = selectRange.startContainer.parentElement;
console.log(utils.GetText(tmpSpan))
let curTxt = utils.GetText(tmpSpan);
if (curTxt.trim().length <= 1) {
return
}
console.dir(select)
console.dir(mutation)
console.dir(grandfatherElement)
console.dir(tmpSpan)
console.log(tmpSpan)
console.log(curTxt.split(''))
let curTxtArr = curTxt.split('');
//保留一个
tmpSpan.innerText = curTxtArr[0];
let lastSpan = tmpSpan;
for (let i = 1; i < curTxtArr.length; i++) {
let tmpSpan = document.createElement("span");
tmpSpan.innerText = curTxtArr[i];
utils.InsertAfter(lastSpan, tmpSpan);
lastSpan = tmpSpan;
}
//选区调整
console.log("lastSpan : ", lastSpan)
utils.GetSelection().setPosition(lastSpan, 1);
} else {
console.log("TODO 暂时不支持")
}
} else {
console.log("TODO 暂时不支持")
}
} else {
other(mutation);
}