Browse Source

:bug: https://github.com/siyuan-note/siyuan/issues/174

Vanessa 2 years ago
parent
commit
bab9a27cac

+ 4 - 0
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;

+ 4 - 3
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  // 为空的时候需要等于
         ) {

+ 1 - 5
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;
                 }
             });