add:输入分解
This commit is contained in:
parent
64f268ef8f
commit
70eff9141b
@ -47,6 +47,8 @@ define(function (require, exports, module) {
|
|||||||
//最近一次操作
|
//最近一次操作
|
||||||
this.latestOpDoc = null;
|
this.latestOpDoc = null;
|
||||||
|
|
||||||
|
//Compositionstart
|
||||||
|
this.Compositionstart = false
|
||||||
|
|
||||||
//初始化
|
//初始化
|
||||||
}
|
}
|
||||||
@ -66,7 +68,7 @@ define(function (require, exports, module) {
|
|||||||
return this.rowNo++;
|
return this.rowNo++;
|
||||||
}
|
}
|
||||||
|
|
||||||
getCurRowNo(){
|
getCurRowNo() {
|
||||||
return this.rowNo
|
return this.rowNo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,6 +154,17 @@ define(function (require, exports, module) {
|
|||||||
//兼容IE
|
//兼容IE
|
||||||
targetElement.fireEvent('focus');
|
targetElement.fireEvent('focus');
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取元素
|
||||||
|
* @param element
|
||||||
|
* @returns {string|string|*}
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GetText(element) {
|
||||||
|
//textContent 性能 准确性更好
|
||||||
|
return element.textContent || element.innerText;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,11 @@ define(function (require, exports, module) {
|
|||||||
characterDataOldValue: true
|
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);
|
document.getElementById("_style_utils").addEventListener("mousedown", this.Mousedown, false);
|
||||||
@ -125,9 +130,8 @@ define(function (require, exports, module) {
|
|||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
CompositionstartListener(e) {
|
CompositionstartListener(e) {
|
||||||
const utils = require('../common/utils');
|
const ctx = require('../common/ctx');
|
||||||
const event = utils.ParseEvent(e);
|
ctx.Compositionstart = true
|
||||||
// window.myEdit.biz.compositionstartHandle(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -136,10 +140,8 @@ define(function (require, exports, module) {
|
|||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
CompositionendListener(e) {
|
CompositionendListener(e) {
|
||||||
const utils = require('../common/utils');
|
const ctx = require('../common/ctx');
|
||||||
const event = utils.ParseEvent(e);
|
ctx.Compositionstart = false
|
||||||
console.log("Compositionend : ", event)
|
|
||||||
// window.myEdit.biz.compositionendHandle(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,6 +27,10 @@ define(function (require, exports, module) {
|
|||||||
//回车事件,禁止处理。防止生成 div
|
//回车事件,禁止处理。防止生成 div
|
||||||
if (keyCode === 13) {
|
if (keyCode === 13) {
|
||||||
// utils.ProhibitDefaultEvent(event);
|
// utils.ProhibitDefaultEvent(event);
|
||||||
|
|
||||||
|
// const enterHandle = require('./EnterEventImpl')
|
||||||
|
// enterHandle.handle(e);
|
||||||
|
// return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//在鼠标按下的时候删除,体验更好
|
//在鼠标按下的时候删除,体验更好
|
||||||
|
@ -20,7 +20,7 @@ define(function (require, exports, module) {
|
|||||||
if (keyCombination && keyCode === 67) {
|
if (keyCombination && keyCode === 67) {
|
||||||
// 阻止默认事件
|
// 阻止默认事件
|
||||||
// utils.ProhibitDefaultEvent(event);
|
// utils.ProhibitDefaultEvent(event);
|
||||||
// console.log('触发ctrl + c 事件', e.target)
|
console.log('触发ctrl + c 事件', e.target)
|
||||||
}
|
}
|
||||||
|
|
||||||
//撤销
|
//撤销
|
||||||
|
@ -105,18 +105,56 @@ define(function (require, exports, module) {
|
|||||||
let target = mutation.target;
|
let target = mutation.target;
|
||||||
if (target.nodeType === 3 && target.nodeName === "#text") {
|
if (target.nodeType === 3 && target.nodeName === "#text") {
|
||||||
// console.log(
|
// console.log(
|
||||||
// "target: ", target,
|
// "updateText target: ", target,
|
||||||
// "\nnodeType: ", target.nodeType,
|
// "\nnodeType: ", target.nodeType,
|
||||||
// "\nnodeName: ", target.nodeName,
|
// "\nnodeName: ", target.nodeName,
|
||||||
// "\ndata: ", target.value,
|
// "\ndata: ", target.value,
|
||||||
// "\nparentNode: ", target.parentNode,
|
// "\nparentNode: ", target.parentNode,
|
||||||
// "\nparentNode_parentNode: ", target.parentNode.parentNode,
|
// "\nparentNode_parentNode: ", target.parentNode?.parentNode,
|
||||||
// )
|
// )
|
||||||
|
|
||||||
// let curSpan = target.parentNode;
|
let grandfatherElement = target.parentNode?.parentElement;
|
||||||
// let curP = target.parentNode.parentNode;
|
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 {
|
} else {
|
||||||
other(mutation);
|
other(mutation);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user