From 9ea365276eee2f5b0b8d7e6d4e81c7ce2407ed2f Mon Sep 17 00:00:00 2001 From: Vanessa Date: Thu, 22 Sep 2022 10:02:13 +0800 Subject: [PATCH] :bug: fix https://github.com/siyuan-note/insider/issues/1075 --- app/appearance/icons/ant/icon.js | 2 +- app/appearance/icons/ant/icon.json | 2 +- app/src/protyle/util/Options.ts | 11 ++--- app/src/protyle/wysiwyg/keydown.ts | 76 +++++++++++++++--------------- 4 files changed, 46 insertions(+), 45 deletions(-) diff --git a/app/appearance/icons/ant/icon.js b/app/appearance/icons/ant/icon.js index f51328db6..7efa2e547 100644 --- a/app/appearance/icons/ant/icon.js +++ b/app/appearance/icons/ant/icon.js @@ -1,7 +1,7 @@ document.body.insertAdjacentHTML('afterBegin', ` - + diff --git a/app/appearance/icons/ant/icon.json b/app/appearance/icons/ant/icon.json index 7309d639b..acfb694a3 100644 --- a/app/appearance/icons/ant/icon.json +++ b/app/appearance/icons/ant/icon.json @@ -2,5 +2,5 @@ "name": "ant", "author": "Vanessa", "url": "https://github.com/Vanessa219", - "version": "1.0.7" + "version": "1.0.8" } diff --git a/app/src/protyle/util/Options.ts b/app/src/protyle/util/Options.ts index 1cba7bb27..7bc1ca47d 100644 --- a/app/src/protyle/util/Options.ts +++ b/app/src/protyle/util/Options.ts @@ -80,22 +80,22 @@ export class Options { toolbar: isMobile() ? [ "block-ref", "a", - "text", "|", + "text", "strong", "em", "u", + "clear", + "|", "code", "tag", "inline-memo", "inline-math", - "|", - "clear", ] : [ "block-ref", "a", - "text", "|", + "text", "strong", "em", "u", @@ -103,14 +103,13 @@ export class Options { "mark", "sup", "sub", + "clear", "|", "code", "kbd", "tag", "inline-memo", "inline-math", - "|", - "clear" ], typewriterMode: false, upload: { diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts index 4250f79c2..6a419feb1 100644 --- a/app/src/protyle/wysiwyg/keydown.ts +++ b/app/src/protyle/wysiwyg/keydown.ts @@ -514,47 +514,49 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { if (matchHotKey("⌘/", event)) { event.stopPropagation(); event.preventDefault(); - const selectElements = protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"); - if (selectElements.length > 0) { - if (selectElements.length === 1) { - protyle.gutter.renderMenu(protyle, selectElements[0]); - } else { - protyle.gutter.renderMultipleMenu(protyle, Array.from(selectElements)); + const selectElements = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select")); + if (selectElements.length === 0) { + const inlineElement = hasClosestByAttribute(range.startContainer, "data-type", null); + if (inlineElement) { + const types = inlineElement.getAttribute("data-type").split(" "); + if (types.includes("block-ref")) { + refMenu(protyle, inlineElement); + return; + } else if (types.includes("inline-memo")) { + protyle.toolbar.showRender(protyle, inlineElement); + return; + } else if (types.includes("file-annotation-ref")) { + protyle.toolbar.showFileAnnotationRef(protyle, inlineElement); + return; + } else if (types.includes("a")) { + linkMenu(protyle, inlineElement); + return; + } } - const rect = nodeElement.getBoundingClientRect(); - window.siyuan.menus.menu.popup({x: rect.left, y: rect.top}, true); - return; - } - const inlineElement = hasClosestByAttribute(range.startContainer, "data-type", null); - if (inlineElement) { - const types = inlineElement.getAttribute("data-type").split(" "); - if (types.includes("block-ref")) { - refMenu(protyle, inlineElement); - return; - } else if (types.includes("inline-memo")) { - protyle.toolbar.showRender(protyle, inlineElement); - return; - } else if (types.includes("file-annotation-ref")) { - protyle.toolbar.showFileAnnotationRef(protyle, inlineElement); - return; - } else if (types.includes("a")) { - linkMenu(protyle, inlineElement); - return; + + // https://github.com/siyuan-note/siyuan/issues/5185 + if (range.startOffset === 0 && range.startContainer.nodeType === 3) { + const previousSibling = hasPreviousSibling(range.startContainer) as HTMLElement; + if (previousSibling && previousSibling.nodeType !== 3 && previousSibling.getAttribute("data-type").indexOf("inline-math") > -1) { + protyle.toolbar.showRender(protyle, previousSibling); + return; + } else if (!previousSibling && + range.startContainer.parentElement.previousSibling && range.startContainer.parentElement.previousSibling.isSameNode(range.startContainer.parentElement.previousElementSibling) && + range.startContainer.parentElement.previousElementSibling.getAttribute("data-type").indexOf("inline-math") > -1) { + protyle.toolbar.showRender(protyle, range.startContainer.parentElement.previousElementSibling); + return; + } } + + selectElements.push(nodeElement); } - // https://github.com/siyuan-note/siyuan/issues/5185 - if (range.startOffset === 0 && range.startContainer.nodeType === 3) { - const previousSibling = hasPreviousSibling(range.startContainer) as HTMLElement; - if (previousSibling && previousSibling.nodeType !== 3 && previousSibling.getAttribute("data-type").indexOf("inline-math") > -1) { - protyle.toolbar.showRender(protyle, previousSibling); - return; - } else if (!previousSibling && - range.startContainer.parentElement.previousSibling && range.startContainer.parentElement.previousSibling.isSameNode(range.startContainer.parentElement.previousElementSibling) && - range.startContainer.parentElement.previousElementSibling.getAttribute("data-type").indexOf("inline-math") > -1) { - protyle.toolbar.showRender(protyle, range.startContainer.parentElement.previousElementSibling); - return; - } + if (selectElements.length === 1) { + protyle.gutter.renderMenu(protyle, selectElements[0]); + } else { + protyle.gutter.renderMultipleMenu(protyle, selectElements); } + const rect = nodeElement.getBoundingClientRect(); + window.siyuan.menus.menu.popup({x: rect.left, y: rect.top}, true); return; }