From 20e6445f86f72e64e8f613401fc89acc7e64fdbb Mon Sep 17 00:00:00 2001 From: Vanessa Date: Wed, 13 Mar 2024 00:19:06 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/10592 --- app/src/protyle/wysiwyg/remove.ts | 22 +++++++++++----------- app/src/protyle/wysiwyg/transaction.ts | 5 +++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/app/src/protyle/wysiwyg/remove.ts b/app/src/protyle/wysiwyg/remove.ts index 01a50cea8..a556b57f4 100644 --- a/app/src/protyle/wysiwyg/remove.ts +++ b/app/src/protyle/wysiwyg/remove.ts @@ -351,14 +351,6 @@ export const removeBlock = (protyle: IProtyle, blockElement: Element, range: Ran } return; } - if (blockElement.getAttribute("data-type") === "NodeHeading") { - turnsIntoTransaction({ - protyle: protyle, - selectsElement: [blockElement], - type: "Blocks2Ps", - }); - return; - } if (!blockElement.previousElementSibling && blockElement.parentElement.getAttribute("data-type") === "NodeBlockquote") { range.insertNode(document.createElement("wbr")); const blockParentElement = blockElement.parentElement; @@ -404,7 +396,15 @@ export const removeBlock = (protyle: IProtyle, blockElement: Element, range: Ran removeLi(protyle, blockElement, range, type === "Delete"); return; } - + if (blockElement.getAttribute("data-type") === "NodeHeading") { + turnsIntoTransaction({ + protyle: protyle, + selectsElement: [blockElement], + type: "Blocks2Ps", + range: moveToPrevious(blockElement, range, type === "Delete") + }); + return; + } if (blockElement.previousElementSibling && blockElement.previousElementSibling.classList.contains("protyle-breadcrumb__bar")) { return; } @@ -558,14 +558,14 @@ export const moveToPrevious = (blockElement: Element, range: Range, isDelete: bo if (previousBlockElement) { const previousEditElement = getContenteditableElement(getLastBlock(previousBlockElement)); if (previousEditElement) { - setLastNodeRange(previousEditElement, range, false); + return setLastNodeRange(previousEditElement, range, false); } } } }; // https://github.com/siyuan-note/siyuan/issues/10393 -export const removeImage = (imgSelectElement: Element, nodeElement:HTMLElement, range:Range, protyle:IProtyle) => { +export const removeImage = (imgSelectElement: Element, nodeElement: HTMLElement, range: Range, protyle: IProtyle) => { const oldHTML = nodeElement.outerHTML; const imgPreviousSibling = hasPreviousSibling(imgSelectElement); if (imgPreviousSibling && imgPreviousSibling.textContent.endsWith(Constants.ZWSP)) { diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.ts index 155234e4d..4a47aa7eb 100644 --- a/app/src/protyle/wysiwyg/transaction.ts +++ b/app/src/protyle/wysiwyg/transaction.ts @@ -856,6 +856,7 @@ export const turnsIntoTransaction = (options: { type: TTurnInto, level?: number, isContinue?: boolean, + range?: Range }) => { let selectsElement: Element[] = options.selectsElement; let range: Range; @@ -977,8 +978,8 @@ export const turnsIntoTransaction = (options: { highlightRender(options.protyle.wysiwyg.element); avRender(options.protyle.wysiwyg.element, options.protyle); blockRender(options.protyle, options.protyle.wysiwyg.element); - if (range) { - focusByWbr(options.protyle.wysiwyg.element, range); + if (range || options.range) { + focusByWbr(options.protyle.wysiwyg.element, range || options.range); } else { focusBlock(options.protyle.wysiwyg.element.querySelector(`[data-node-id="${selectsElement[0].getAttribute("data-node-id")}"]`)); }