From 25b577fbee34062df4ee3b7961c4a7aefcc5d2d6 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Fri, 8 Jul 2022 11:20:08 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/5364 --- app/src/menus/protyle.ts | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts index 4e9f5ce49..5f1cedf09 100644 --- a/app/src/menus/protyle.ts +++ b/app/src/menus/protyle.ts @@ -594,9 +594,13 @@ export const linkMenu = (protyle: IProtyle, linkElement: HTMLElement, focusText if ((event.key === "Enter" || event.key === "Escape") && !event.isComposing) { event.preventDefault(); event.stopPropagation(); - protyle.toolbar.range.selectNodeContents(linkElement); - protyle.toolbar.range.collapse(false); - focusByRange(protyle.toolbar.range); + if (linkElement.textContent === "" || linkElement.textContent === Constants.ZWSP) { + protyle.toolbar.setInlineMark(protyle, "link", "remove"); + } else { + protyle.toolbar.range.selectNodeContents(linkElement); + protyle.toolbar.range.collapse(false); + focusByRange(protyle.toolbar.range); + } window.siyuan.menus.menu.remove(); } }); @@ -627,9 +631,13 @@ export const linkMenu = (protyle: IProtyle, linkElement: HTMLElement, focusText if ((event.key === "Enter" || event.key === "Escape") && !event.isComposing) { event.preventDefault(); event.stopPropagation(); - protyle.toolbar.range.selectNodeContents(linkElement); - protyle.toolbar.range.collapse(false); - focusByRange(protyle.toolbar.range); + if (!inputElement.value) { + protyle.toolbar.setInlineMark(protyle, "link", "remove"); + } else { + protyle.toolbar.range.selectNodeContents(linkElement); + protyle.toolbar.range.collapse(false); + focusByRange(protyle.toolbar.range); + } window.siyuan.menus.menu.remove(); } }); @@ -653,9 +661,13 @@ export const linkMenu = (protyle: IProtyle, linkElement: HTMLElement, focusText if ((event.key === "Enter" || event.key === "Escape") && !event.isComposing) { event.preventDefault(); event.stopPropagation(); - protyle.toolbar.range.selectNodeContents(linkElement); - protyle.toolbar.range.collapse(false); - focusByRange(protyle.toolbar.range); + if (linkElement.textContent === "" || linkElement.textContent === Constants.ZWSP) { + protyle.toolbar.setInlineMark(protyle, "link", "remove"); + } else { + protyle.toolbar.range.selectNodeContents(linkElement); + protyle.toolbar.range.collapse(false); + focusByRange(protyle.toolbar.range); + } window.siyuan.menus.menu.remove(); } });