From bab9a27cacc19a5a6b0a3fb9b180e7da9c13803c Mon Sep 17 00:00:00 2001 From: Vanessa Date: Sun, 18 Sep 2022 20:20:53 +0800 Subject: [PATCH] :bug: https://github.com/siyuan-note/siyuan/issues/174 --- app/src/protyle/toolbar/index.ts | 4 ++++ app/src/protyle/wysiwyg/index.ts | 7 ++++--- app/src/protyle/wysiwyg/keydown.ts | 6 +----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts index 15f119122..539ec4325 100644 --- a/app/src/protyle/toolbar/index.ts +++ b/app/src/protyle/toolbar/index.ts @@ -234,6 +234,10 @@ export class Toolbar { } public setInlineMark(protyle: IProtyle, type: string, action: "range" | "toolbar", textObj?: ITextOption) { + if (["text", "a", "block-ref", "inline-math", "inline-memo"].includes(type)) { + protyle.toolbar.element.querySelector(`[data-type="${type}"]`).dispatchEvent(new CustomEvent("block-ref" === type ? getEventName() : "click")); + return; + } const nodeElement = hasClosestBlock(this.range.startContainer); if (!nodeElement) { return; diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts index f4612ef3c..42be15bc8 100644 --- a/app/src/protyle/wysiwyg/index.ts +++ b/app/src/protyle/wysiwyg/index.ts @@ -112,11 +112,12 @@ export class WYSIWYG { const inputData = event.data; protyle.toolbar.range = range; const inlineElement = range.startContainer.parentElement; - const currentTypes = protyle.toolbar.getCurrentType(); + const currentTypes = protyle.toolbar.getCurrentType(); if (// 表格行内公式之前无法插入文字 https://github.com/siyuan-note/siyuan/issues/3908 - inlineElement.tagName==="SPAN" && + inlineElement.tagName === "SPAN" && + inlineElement.textContent.replace(Constants.ZWSP, "") !== inputData && range.toString() === "" && range.startContainer.nodeType === 3 && - (currentTypes.includes("inline-memo") || currentTypes.includes("text") || currentTypes.includes("block-ref")|| currentTypes.includes("file-annotation-ref")|| currentTypes.includes("a")) && + (currentTypes.includes("inline-memo") || currentTypes.includes("text") || currentTypes.includes("block-ref") || currentTypes.includes("file-annotation-ref") || currentTypes.includes("a")) && !hasNextSibling(range.startContainer) && range.startContainer.textContent.length === range.startOffset && inlineElement.textContent.replace(Constants.ZWSP, "").length >= inputData.length // 为空的时候需要等于 ) { diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts index d812e0310..0cf3d2b12 100644 --- a/app/src/protyle/wysiwyg/keydown.ts +++ b/app/src/protyle/wysiwyg/keydown.ts @@ -1183,11 +1183,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { } if (matchHotKey(menuItem.hotkey, event)) { protyle.toolbar.range = getEditorRange(protyle.wysiwyg.element); - if (["text", "a", "block-ref", "inline-math", "inline-memo"].includes(menuItem.name)) { - protyle.toolbar.element.querySelector(`[data-type="${menuItem.name}"]`).dispatchEvent(new CustomEvent("block-ref" === menuItem.name ? getEventName() : "click")); - } else { - protyle.toolbar.setInlineMark(protyle, menuItem.name, "range"); - } + protyle.toolbar.setInlineMark(protyle, menuItem.name, "range"); return true; } });