This commit is contained in:
shaoyongjun 2024-10-31 19:28:20 +08:00
parent 258fed649b
commit a49ec71091
3 changed files with 29 additions and 12 deletions

View File

@ -185,7 +185,7 @@ export class MyBiz {
newParagraph.setAttribute("data-id", uuid)
newParagraph.setAttribute("id", uuid)
newParagraph.setAttribute("data-order", rowNo)
newParagraph.onkeydown = window.myEdit.eventListener.KeydownListener
newParagraph.onkeyup = window.myEdit.eventListener.KeydownListener
// newParagraph.innerHTML = "<br>"
window.myEdit.ctx.MyRoot.appendChild(newParagraph)
window.myEdit.ctx.MyDocMap.set(rowNo, new MyMapItem(uuid))
@ -209,7 +209,7 @@ export class MyBiz {
/**
* 更新文档
* @param {*} e
* @param {*} curP
*/
updateText(curP) {
if (window.myEdit.ctx.inCompositionEvent) {
@ -244,12 +244,17 @@ export class MyBiz {
let myDocItem = new MyDocItem(curP);
let inputLength = curP.innerText.length
console.log("emptyKeyWorkHandler :", curP, " _'", curP.innerHTML, "'_'", curP.innerText, "'_",
"\neq00", curP.innerHTML.startsWith("&nbsp;#&nbsp;"),
"\neq01", curP.innerHTML.startsWith(" # "),
"\neq1", curP.innerText.startsWith("#&nbsp;"),
"\neq2", curP.innerText.startsWith("#"),
"\neq1", curP.innerHTML.startsWith("&nbsp;#&nbsp;"),
"\neq2", curP.innerHTML.startsWith(" # "),
"\neq3", curP.innerHTML.startsWith("#&nbsp;"),
"\neq4", curP.innerHTML.startsWith("# "))
"\neq4", curP.innerHTML.startsWith("# "),
"\neqV1", curP.innerText.startsWith("&nbsp;#&nbsp;"),
"\neqV2", curP.innerText.startsWith(" # "),
"\neqV3", curP.innerText.startsWith("#&nbsp;"),
"\neqV4", curP.innerText.startsWith("# "),
)
/**
* h1 ~ h6
*/
@ -349,7 +354,7 @@ export class MyBiz {
newParagraph.setAttribute("data-id", curP.getAttribute("data-id"))
newParagraph.setAttribute("id", curP.getAttribute("data-id"))
newParagraph.setAttribute("data-order", curP.getAttribute("data-order"))
newParagraph.onkeydown = window.myEdit.eventListener.KeydownListener
newParagraph.onkeyup = window.myEdit.eventListener.KeydownListener
//todo 支持 有数据的行 在行首输入 #
// if()

View File

@ -67,13 +67,23 @@ export class MyEventListener {
* @param e
* @constructor
*/
WindowsCtrZHandle(e) {
WindowsKeydownHandle(e) {
const event = window.myEdit.utils.ParseEvent(e);
const keyCode = window.myEdit.utils.GetKeyCode(event);
const metaKey = event.metaKey;
let testDiv = document.getElementById("testDevice")
testDiv.innerText = "键盘输入: keyCode:" + keyCode +
"\nmetaKey:" + metaKey;
if (metaKey && keyCode === 90) {
window.myEdit.biz.cancelHandle(event);
}
//回车事件,禁止处理。防止生成 div
if (keyCode === 13) {
window.myEdit.utils.ProhibitDefaultEvent(event);
}
}
/**

View File

@ -108,9 +108,11 @@ import {MyEventListener} from "./event/MyEventListener.js";
window.addEventListener('resize', window.myEdit.utils.RefreshRootFrontSize);
window.addEventListener('resize', window.myEdit.utils.RefreshBodyFrontSize);
/**
* 窗口撤销事件
* 窗口撤销事件.
* js中的键盘事件只有三种keydownkeyupkeypress它们触发的顺序是keydown -> keypress -> keyup当按下一个键不放开一般会重复地触发 keydown+keypress直到放开后触发一个 keyup 事件
*
*/
window.addEventListener('keydown', window.myEdit.eventListener.WindowsCtrZHandle, true);
window.addEventListener('keydown', window.myEdit.eventListener.WindowsKeydownHandle, true);
}());
/**
@ -137,7 +139,7 @@ window.onload = function () {
newParagraph.setAttribute("data-id", uuid)
newParagraph.setAttribute("id", uuid)
newParagraph.setAttribute("data-order", curOrder)
newParagraph.onkeydown = window.myEdit.eventListener.KeydownListener
newParagraph.onkeyup = window.myEdit.eventListener.KeydownListener
// newParagraph.innerHTML = "<br>"
//添加一行
window.myEdit.utils.AddNewParagraph(newParagraph);