diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts index 4913f58ae05..9b40ce40409 100644 --- a/app/src/protyle/wysiwyg/index.ts +++ b/app/src/protyle/wysiwyg/index.ts @@ -4,7 +4,8 @@ import { hasClosestByAttribute, hasClosestByClassName, hasClosestByMatchTag, - hasTopClosestByClassName, isInEmbedBlock, + hasTopClosestByClassName, + isInEmbedBlock, } from "../util/hasClosest"; import { focusBlock, @@ -12,7 +13,8 @@ import { focusByWbr, focusSideBlock, getEditorRange, - getSelectionOffset, setFirstNodeRange, + getSelectionOffset, + setFirstNodeRange, setLastNodeRange, } from "../util/selection"; import {Constants} from "../../constants"; @@ -23,7 +25,8 @@ import { contentMenu, enterBack, fileAnnotationRefMenu, - imgMenu, inlineMathMenu, + imgMenu, + inlineMathMenu, linkMenu, refMenu, setFold, @@ -2004,16 +2007,7 @@ export class WYSIWYG { // 输入法测试点 https://github.com/siyuan-note/siyuan/issues/3027 let isComposition = false; // for iPhone - this.element.addEventListener("compositionstart", (event) => { - // 搜狗输入法划选输入后无 data https://github.com/siyuan-note/siyuan/issues/4672 - const range = getEditorRange(protyle.wysiwyg.element); - const nodeElement = hasClosestBlock(range.startContainer); - if (nodeElement && typeof protyle.wysiwyg.lastHTMLs[nodeElement.getAttribute("data-node-id")] === "undefined") { - range.insertNode(document.createElement("wbr")); - protyle.wysiwyg.lastHTMLs[nodeElement.getAttribute("data-node-id")] = nodeElement.outerHTML; - nodeElement.querySelector("wbr").remove(); - } - isComposition = true; + this.element.addEventListener("compositionstart", (event) => {isComposition = true; event.stopPropagation(); }); @@ -2085,23 +2079,26 @@ export class WYSIWYG { this.element.addEventListener("keyup", (event) => { const range = getEditorRange(this.element).cloneRange(); const nodeElement = hasClosestBlock(range.startContainer); - if (event.key !== "PageUp" && event.key !== "PageDown" && event.key !== "Home" && event.key !== "End" && event.key.indexOf("Arrow") === -1 && - event.key !== "Alt" && event.key !== "Shift" && event.key !== "CapsLock" && event.key !== "Escape" && event.key !== "Meta" && !/^F\d{1,2}$/.test(event.key) && - (!event.isComposing || (event.isComposing && range.toString() !== "")) // https://github.com/siyuan-note/siyuan/issues/4341 - ) { + + if ( event.key !== "PageUp" && event.key !== "PageDown" && event.key !== "Home" && event.key !== "End" && + event.key.indexOf("Arrow") === -1 && event.key !== "Escape" && event.key !== "Shift" && + event.key !== "Meta" && event.key !== "Alt" && event.key !== "Control" && event.key !== "CapsLock" && + !event.ctrlKey && !event.shiftKey && !event.metaKey && !event.altKey&& + !/^F\d{1,2}$/.test(event.key) ){ // 搜狗输入法不走 keydown,需重新记录历史状态 - if (range.toString() === "" && // windows 下回车新建块输入abc,选中 bc ctrl+m 后光标错误 - (!this.preventKeyup || event.code === "Space") && - nodeElement && typeof protyle.wysiwyg.lastHTMLs[nodeElement.getAttribute("data-node-id")] === "undefined") { + if ( nodeElement && + ( typeof protyle.wysiwyg.lastHTMLs[nodeElement.getAttribute("data-node-id")] === "undefined"||range.toString()!==""||!this.preventKeyup)) { range.insertNode(document.createElement("wbr")); protyle.wysiwyg.lastHTMLs[nodeElement.getAttribute("data-node-id")] = nodeElement.outerHTML; nodeElement.querySelector("wbr").remove(); } + this.preventKeyup = false; return; } // 需放在 lastHTMLs 后,否则 https://github.com/siyuan-note/siyuan/issues/4388 if (this.preventKeyup) { + this.preventKeyup = false; return; } diff --git a/app/src/protyle/wysiwyg/input.ts b/app/src/protyle/wysiwyg/input.ts index 521392974ef..5d963618403 100644 --- a/app/src/protyle/wysiwyg/input.ts +++ b/app/src/protyle/wysiwyg/input.ts @@ -298,6 +298,7 @@ const updateInput = (html: string, protyle: IProtyle, id: string) => { data: protyle.wysiwyg.lastHTMLs[id], action: "update" }); + protyle.wysiwyg.lastHTMLs[id] = item.outerHTML; } else { let firstElement; if (index === 0) { diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts index 6524bcd02ad..bc0646ba560 100644 --- a/app/src/protyle/wysiwyg/keydown.ts +++ b/app/src/protyle/wysiwyg/keydown.ts @@ -166,15 +166,14 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { // 有可能输入 shift+. ,因此需要使用 event.key 来进行判断 if (event.key !== "PageUp" && event.key !== "PageDown" && event.key !== "Home" && event.key !== "End" && event.key.indexOf("Arrow") === -1 && event.key !== "Escape" && event.key !== "Shift" && event.key !== "Meta" && event.key !== "Alt" && event.key !== "Control" && event.key !== "CapsLock" && - !isNotEditBlock(nodeElement) && !/^F\d{1,2}$/.test(event.key)) { + !isNotEditBlock(nodeElement) && !event.ctrlKey && !event.shiftKey && !event.metaKey && !event.altKey&&!/^F\d{1,2}$/.test(event.key)) { const cloneRange = range.cloneRange(); range.insertNode(document.createElement("wbr")); protyle.wysiwyg.lastHTMLs[nodeElement.getAttribute("data-node-id")] = nodeElement.outerHTML; nodeElement.querySelector("wbr").remove(); // 光标位于引用结尾后 ctrl+b 偶尔会失效 range = cloneRange; - // 会导致 protyle.toolbar.range 和 range 不一致,先在有问题的地方重置一下 https://github.com/siyuan-note/siyuan/issues/10933 - protyle.wysiwyg.preventKeyup = true; // 搜狗输入法进入此代码记录的话,keyup 就不再记录,否则 transaction 清空后 keyup 再次记录,下一次 keydown 就不会记录 https://github.com/siyuan-note/siyuan/issues/13244 + protyle.wysiwyg.preventKeyup = true; } if (!window.siyuan.menus.menu.element.classList.contains("fn__none") && diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.ts index b779d25f198..5c8adb8bdc9 100644 --- a/app/src/protyle/wysiwyg/transaction.ts +++ b/app/src/protyle/wysiwyg/transaction.ts @@ -1121,7 +1121,6 @@ export const transaction = (protyle: IProtyle, doOperations: IOperation[], undoO protyle.transactionTime - time < Constants.TIMEOUT_INPUT) { needDebounce = true; } - protyle.wysiwyg.lastHTMLs = {}; if (undoOperations) { if (window.siyuan.config.fileTree.openFilesUseCurrentTab && protyle.model) { protyle.model.headElement.classList.remove("item--unupdate");