From 48f4b4f4ecd610a9e21fbf1b91be0a4a7a2cf131 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A2=96=E9=80=B8?= <49649786+Zuoqiu-Yingyi@users.noreply.github.com> Date: Sat, 2 Sep 2023 03:53:07 +0800 Subject: [PATCH] :bug: fix the issue of can't open block menu when the cursor is located in an empty code block --- app/src/protyle/wysiwyg/keydown.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts index f62c47ef785..fc4c056f296 100644 --- a/app/src/protyle/wysiwyg/keydown.ts +++ b/app/src/protyle/wysiwyg/keydown.ts @@ -555,12 +555,17 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { // 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) { + 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) { + 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; }