From 30ff7c0d13d8a70d11c14006197e27107a973aff Mon Sep 17 00:00:00 2001 From: Vanessa Date: Sun, 28 Dec 2025 16:54:30 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/16703 --- app/src/block/util.ts | 3 ++- app/src/protyle/util/editorCommonEvent.ts | 6 ++++-- app/src/protyle/wysiwyg/enter.ts | 18 ++++++++++-------- app/src/protyle/wysiwyg/list.ts | 3 ++- app/src/protyle/wysiwyg/remove.ts | 3 ++- app/src/protyle/wysiwyg/transaction.ts | 17 +++++++++++++---- 6 files changed, 33 insertions(+), 17 deletions(-) diff --git a/app/src/block/util.ts b/app/src/block/util.ts index 95b1df00f..c45fc20b2 100644 --- a/app/src/block/util.ts +++ b/app/src/block/util.ts @@ -191,7 +191,8 @@ export const insertEmptyBlock = (protyle: IProtyle, position: InsertPosition, id protyle, selectsElement: position === "afterend" ? [blockElement, blockElement.nextElementSibling] : [blockElement.previousElementSibling, blockElement], type: "BlocksMergeSuperBlock", - level: "row" + level: "row", + unfocus: true, }); } focusByWbr(protyle.wysiwyg.element, range); diff --git a/app/src/protyle/util/editorCommonEvent.ts b/app/src/protyle/util/editorCommonEvent.ts index cda011467..1ccc01a61 100644 --- a/app/src/protyle/util/editorCommonEvent.ts +++ b/app/src/protyle/util/editorCommonEvent.ts @@ -426,7 +426,8 @@ const dragSb = async (protyle: IProtyle, sourceElements: Element[], targetElemen protyle, selectsElement: newSourceParentElement.reverse(), type: "BlocksMergeSuperBlock", - level: "row" + level: "row", + unfocus: true, }); } if (document.contains(sourceElements[0])) { @@ -515,7 +516,8 @@ const dragSame = async (protyle: IProtyle, sourceElements: Element[], targetElem protyle, selectsElement: newSourceParentElement.reverse(), type: "BlocksMergeSuperBlock", - level: "row" + level: "row", + unfocus: true, }); } if (document.contains(sourceElements[0])) { diff --git a/app/src/protyle/wysiwyg/enter.ts b/app/src/protyle/wysiwyg/enter.ts index 59f4bb7e2..7a94aa0f8 100644 --- a/app/src/protyle/wysiwyg/enter.ts +++ b/app/src/protyle/wysiwyg/enter.ts @@ -1,7 +1,7 @@ import {genEmptyElement, genHeadingElement, insertEmptyBlock} from "../../block/util"; import {focusByRange, focusByWbr, getSelectionOffset, setLastNodeRange} from "../util/selection"; import { - getContenteditableElement, + getContenteditableElement, getParentBlock, getTopEmptyElement, hasNextSibling, hasPreviousSibling, @@ -117,12 +117,10 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle } // bq || callout - const isCallout = blockElement.parentElement.classList.contains("callout-content"); - const parentBlockElement = isCallout ? blockElement.parentElement.parentElement : blockElement.parentElement; if (editableElement.textContent.replace(Constants.ZWSP, "").replace("\n", "") === "" && ((blockElement.nextElementSibling && blockElement.nextElementSibling.classList.contains("protyle-attr") && blockElement.parentElement.getAttribute("data-type") === "NodeBlockquote") || - (isCallout && !blockElement.nextElementSibling))) { + (blockElement.parentElement.classList.contains("callout-content") && !blockElement.nextElementSibling))) { range.insertNode(document.createElement("wbr")); const topElement = getTopEmptyElement(blockElement); const blockId = blockElement.getAttribute("data-node-id"); @@ -137,6 +135,7 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle id: topId, data: topElement.outerHTML, }; + let parentBlockElement = getParentBlock(blockElement); if (topId === blockId) { doInsert.previousID = parentBlockElement.getAttribute("data-node-id"); undoInsert.previousID = blockElement.previousElementSibling.getAttribute("data-node-id"); @@ -156,13 +155,15 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle action: "delete", id: blockId, }, undoInsert]); + parentBlockElement = getParentBlock(blockElement); if (topId === blockId && parentBlockElement.classList.contains("sb") && parentBlockElement.getAttribute("data-sb-layout") === "col") { turnsIntoOneTransaction({ protyle, selectsElement: [blockElement.previousElementSibling, blockElement], type: "BlocksMergeSuperBlock", - level: "row" + level: "row", + unfocus: true, }); } focusByWbr(blockElement, range); @@ -197,7 +198,7 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle data: newElement.outerHTML, id: newId, previousID: blockElement.previousElementSibling ? blockElement.previousElementSibling.getAttribute("data-node-id") : "", - parentID: parentBlockElement.getAttribute("data-node-id") || protyle.block.parentID + parentID: getParentBlock(blockElement).getAttribute("data-node-id") || protyle.block.parentID }], [{ action: "delete", id: newId, @@ -209,7 +210,7 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle } range.insertNode(document.createElement("wbr")); const html = blockElement.outerHTML; - const parentHTML = parentBlockElement.outerHTML; + const parentHTML = getParentBlock(blockElement).outerHTML; if (range.toString() !== "") { // 选中数学公式后回车取消选中 https://github.com/siyuan-note/siyuan/issues/12637#issuecomment-2381106949 const mathElement = hasClosestByAttribute(range.startContainer, "data-type", "inline-math"); @@ -353,7 +354,8 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle protyle, selectsElement, type: "BlocksMergeSuperBlock", - level: "row" + level: "row", + unfocus: true, }); } focusByWbr(currentElement, range); diff --git a/app/src/protyle/wysiwyg/list.ts b/app/src/protyle/wysiwyg/list.ts index 9f5d686ed..f1669769f 100644 --- a/app/src/protyle/wysiwyg/list.ts +++ b/app/src/protyle/wysiwyg/list.ts @@ -513,7 +513,8 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range: protyle, selectsElement: [liElement, liElement.nextElementSibling], type: "BlocksMergeSuperBlock", - level: "row" + level: "row", + unfocus: true, }); } focusByWbr(parentLiItemElement, range); diff --git a/app/src/protyle/wysiwyg/remove.ts b/app/src/protyle/wysiwyg/remove.ts index 25574d408..666b2fe5f 100644 --- a/app/src/protyle/wysiwyg/remove.ts +++ b/app/src/protyle/wysiwyg/remove.ts @@ -655,7 +655,8 @@ const removeLi = (protyle: IProtyle, blockElement: Element, range: Range, isDele protyle, selectsElement: selectsElement.reverse(), type: "BlocksMergeSuperBlock", - level: "row" + level: "row", + unfocus: true, }); } focusByWbr(protyle.wysiwyg.element, range); diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.ts index fc85b3e28..e9bfa5308 100644 --- a/app/src/protyle/wysiwyg/transaction.ts +++ b/app/src/protyle/wysiwyg/transaction.ts @@ -13,7 +13,7 @@ import {getAllModels} from "../../layout/getAll"; /// #endif import {avRender, refreshAV} from "../render/av/render"; import {removeFoldHeading} from "../util/heading"; -import {genEmptyElement, genSBElement} from "../../block/util"; +import {cancelSB, genEmptyElement, genSBElement} from "../../block/util"; import {hideElements} from "../ui/hideElements"; import {reloadProtyle} from "../util/reload"; import {countBlockWord} from "../../layout/status"; @@ -935,11 +935,12 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, isUndo: } }; -export const turnsIntoOneTransaction = (options: { +export const turnsIntoOneTransaction = async (options: { protyle: IProtyle, selectsElement: Element[], type: TTurnIntoOne, - level?: TTurnIntoOneSub + level?: TTurnIntoOneSub, + unfocus?: boolean }) => { let parentElement: Element; const id = Lute.NewNodeID(); @@ -1048,8 +1049,16 @@ export const turnsIntoOneTransaction = (options: { blockRender(options.protyle, item); } }); + if ((["Blocks2Blockquote", "Blocks2Callout"].includes(options.type) || options.type.endsWith("Ls")) && + parentElement.parentElement.classList.contains("sb") && parentElement.parentElement.childElementCount === 2) { + const cancelOperations = await cancelSB(options.protyle, parentElement.parentElement); + doOperations.push(...cancelOperations.doOperations); + undoOperations.splice(0, 0, ...cancelOperations.undoOperations); + } transaction(options.protyle, doOperations, undoOperations); - focusBlock(options.protyle.wysiwyg.element.querySelector(`[data-node-id="${options.selectsElement[0].getAttribute("data-node-id")}"]`)); + if (!options.unfocus) { + focusBlock(options.protyle.wysiwyg.element.querySelector(`[data-node-id="${options.selectsElement[0].getAttribute("data-node-id")}"]`)); + } hideElements(["gutter"], options.protyle); };