From 862a9a6bebe73ce0129e619855648ee60833e05d Mon Sep 17 00:00:00 2001 From: Vanessa Date: Thu, 26 Sep 2024 10:23:29 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/12468 --- app/src/protyle/wysiwyg/input.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/app/src/protyle/wysiwyg/input.ts b/app/src/protyle/wysiwyg/input.ts index e28f39659..0c9ba96bb 100644 --- a/app/src/protyle/wysiwyg/input.ts +++ b/app/src/protyle/wysiwyg/input.ts @@ -54,14 +54,21 @@ export const input = async (protyle: IProtyle, blockElement: HTMLElement, range: blockElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss")); const wbrElement: HTMLElement = document.createElement("wbr"); range.insertNode(wbrElement); - if (event && event.inputType === "deleteContentForward") { + if (event) { const wbrNextElement = hasNextSibling(wbrElement) as HTMLElement; - if (wbrNextElement && wbrNextElement.nodeType === 1 && !wbrNextElement.textContent.startsWith(Constants.ZWSP)) { - const nextType = (wbrNextElement.getAttribute("data-type") || "").split(" "); - if (nextType.includes("code") || nextType.includes("kbd") || nextType.includes("tag")) { - wbrNextElement.insertAdjacentElement("afterbegin", wbrElement); + if (event.inputType === "deleteContentForward") { + if (wbrNextElement && wbrNextElement.nodeType === 1 && !wbrNextElement.textContent.startsWith(Constants.ZWSP)) { + const nextType = (wbrNextElement.getAttribute("data-type") || "").split(" "); + if (nextType.includes("code") || nextType.includes("kbd") || nextType.includes("tag")) { + wbrNextElement.insertAdjacentElement("afterbegin", wbrElement); + } } } + // https://github.com/siyuan-note/siyuan/issues/12468 + if ((event.inputType === "deleteContentBackward" || event.inputType === "deleteContentForward") && + wbrNextElement && wbrNextElement.nodeType === 1 && wbrNextElement.tagName === "BR") { + wbrNextElement.remove(); + } } const id = blockElement.getAttribute("data-node-id"); if ((type !== "NodeCodeBlock" && type !== "NodeHeading") && // https://github.com/siyuan-note/siyuan/issues/11851