From a78664ff8cf11f143202d6561e9941cdc4d63e93 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Fri, 3 Jan 2025 11:22:41 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/13568 --- app/src/block/util.ts | 13 ++++++++-- app/src/protyle/util/table.ts | 2 +- app/src/protyle/wysiwyg/enter.ts | 9 +++++++ app/src/protyle/wysiwyg/list.ts | 41 +++++++++++++++++++------------- 4 files changed, 46 insertions(+), 19 deletions(-) diff --git a/app/src/block/util.ts b/app/src/block/util.ts index b35ee1dd1..196772f85 100644 --- a/app/src/block/util.ts +++ b/app/src/block/util.ts @@ -2,7 +2,7 @@ import {focusByWbr, getEditorRange} from "../protyle/util/selection"; import {hasClosestBlock} from "../protyle/util/hasClosest"; import {getTopAloneElement} from "../protyle/wysiwyg/getBlock"; import {genListItemElement, updateListOrder} from "../protyle/wysiwyg/list"; -import {transaction, updateTransaction} from "../protyle/wysiwyg/transaction"; +import {transaction, turnsIntoOneTransaction, updateTransaction} from "../protyle/wysiwyg/transaction"; import {scrollCenter} from "../util/highlightById"; import {Constants} from "../constants"; import {hideElements} from "../protyle/ui/hideElements"; @@ -37,7 +37,7 @@ export const cancelSB = (protyle: IProtyle, nodeElement: Element) => { nodeElement.lastElementChild.remove(); // 超级块中的 html 块需要反转义再赋值 https://github.com/siyuan-note/siyuan/issues/13155 nodeElement.querySelectorAll("protyle-html").forEach(item => { - item.setAttribute("data-content" , item.getAttribute("data-content").replace(/</g, "<").replace(/>/g, ">")); + item.setAttribute("data-content", item.getAttribute("data-content").replace(/</g, "<").replace(/>/g, ">")); }); nodeElement.outerHTML = nodeElement.innerHTML; return; @@ -154,6 +154,15 @@ export const insertEmptyBlock = (protyle: IProtyle, position: InsertPosition, id id: newId, }]); } + if (blockElement.parentElement.classList.contains("sb") && + blockElement.parentElement.getAttribute("data-sb-layout") === "col") { + turnsIntoOneTransaction({ + protyle, + selectsElement: position === "afterend" ? [blockElement, blockElement.nextElementSibling] : [blockElement.previousElementSibling, blockElement], + type: "BlocksMergeSuperBlock", + level: "row" + }); + } focusByWbr(protyle.wysiwyg.element, range); scrollCenter(protyle); }; diff --git a/app/src/protyle/util/table.ts b/app/src/protyle/util/table.ts index 96f50083e..f6df3f26b 100644 --- a/app/src/protyle/util/table.ts +++ b/app/src/protyle/util/table.ts @@ -737,7 +737,7 @@ export const clearTableCell = (protyle: IProtyle, tableBlockElement: HTMLElement } }); tableSelectElement.removeAttribute("style"); - if (getSelection().rangeCount>0) { + if (getSelection().rangeCount > 0) { const range = getSelection().getRangeAt(0); if (tableBlockElement.contains(range.startContainer)) { range.insertNode(document.createElement("wbr")); diff --git a/app/src/protyle/wysiwyg/enter.ts b/app/src/protyle/wysiwyg/enter.ts index 8cba280b1..84e082e1b 100644 --- a/app/src/protyle/wysiwyg/enter.ts +++ b/app/src/protyle/wysiwyg/enter.ts @@ -160,6 +160,15 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle action: "delete", id: blockId, }, undoInsert]); + if (topId === blockId && blockElement.parentElement.classList.contains("sb") && + blockElement.parentElement.getAttribute("data-sb-layout") === "col") { + turnsIntoOneTransaction({ + protyle, + selectsElement: [blockElement.previousElementSibling, blockElement], + type: "BlocksMergeSuperBlock", + level: "row" + }); + } focusByWbr(blockElement, range); return true; } diff --git a/app/src/protyle/wysiwyg/list.ts b/app/src/protyle/wysiwyg/list.ts index 1611564db..2245c7173 100644 --- a/app/src/protyle/wysiwyg/list.ts +++ b/app/src/protyle/wysiwyg/list.ts @@ -1,5 +1,5 @@ import {focusByWbr} from "../util/selection"; -import {transaction, updateTransaction} from "./transaction"; +import {transaction, turnsIntoOneTransaction, updateTransaction} from "./transaction"; import {genEmptyBlock} from "../../block/util"; import * as dayjs from "dayjs"; import {Constants} from "../../constants"; @@ -351,8 +351,8 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range: } if (parentLiItemElement.classList.contains("protyle-wysiwyg") || parentLiItemElement.classList.contains("sb") || parentLiItemElement.classList.contains("bq")) { // 顶层列表 - const doOperations: IOperation[] = []; - const undoOperations: IOperation[] = []; + const topDoOperations: IOperation[] = []; + const topUndoOperations: IOperation[] = []; range.collapse(false); moveToPrevious(deleteElement, range, isDelete); range.insertNode(document.createElement("wbr")); @@ -370,13 +370,13 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range: if (!id) { return; } - doOperations.push({ + topDoOperations.push({ action: "move", id, previousID: topPreviousID, parentID: parentLiItemElement.getAttribute("data-node-id") || protyle.block.parentID }); - undoOperations.push({ + topUndoOperations.push({ action: "move", id, previousID: index === 1 ? undefined : topPreviousID, @@ -401,7 +401,7 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range: lastBlockElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss")); lastBlockElement.innerHTML = `
${Constants.ZWSP}
`; previousElement.after(lastBlockElement); - doOperations.push({ + topDoOperations.push({ action: "insert", id: newId, data: lastBlockElement.outerHTML, @@ -410,13 +410,13 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range: } let topOldPreviousID; while (nextElement && !nextElement.classList.contains("protyle-attr")) { - doOperations.push({ + topDoOperations.push({ action: "move", id: nextElement.getAttribute("data-node-id"), previousID: topOldPreviousID || lastBlockElement.lastElementChild.previousElementSibling?.getAttribute("data-node-id"), parentID: lastBlockElement.getAttribute("data-node-id") }); - undoOperations.push({ + topUndoOperations.push({ action: "move", id: nextElement.getAttribute("data-node-id"), parentID: lastBlockElement.getAttribute("data-node-id"), @@ -431,7 +431,7 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range: Array.from(lastBlockElement.children).forEach(orderItem => { const id = orderItem.getAttribute("data-node-id"); if (id) { - undoOperations.push({ + topUndoOperations.push({ action: "update", id, data: orderItem.outerHTML, @@ -442,7 +442,7 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range: Array.from(lastBlockElement.children).forEach(orderItem => { const id = orderItem.getAttribute("data-node-id"); if (id) { - doOperations.push({ + topDoOperations.push({ action: "update", id, data: orderItem.outerHTML, @@ -451,7 +451,7 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range: }); } if (newId) { - undoOperations.push({ + topUndoOperations.push({ action: "delete", id: newId }); @@ -464,7 +464,7 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range: if (liElement.childElementCount === 1) { // 列表只有一项 - doOperations.push({ + topDoOperations.push({ action: "delete", id: liId }); @@ -472,7 +472,7 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range: if (liId === protyle.block.id) { protyle.block.id = protyle.block.parentID; } - undoOperations.splice(0, 0, { + topUndoOperations.splice(0, 0, { action: "insert", data: movedHTML, id: liId, @@ -484,18 +484,27 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range: if (liElement.getAttribute("data-subtype") === "o") { updateListOrder(liElement, startIndex); } - doOperations.push({ + topDoOperations.push({ action: "update", id: liId, data: liElement.outerHTML }); - undoOperations.splice(0, 0, { + topUndoOperations.splice(0, 0, { action: "update", id: liId, data: movedHTML, }); } - transaction(protyle, doOperations, undoOperations); + transaction(protyle, topDoOperations, topUndoOperations); + if (liElement.childElementCount !== 1 && parentLiItemElement.classList.contains("sb") && + parentLiItemElement.getAttribute("data-sb-layout") === "col") { + turnsIntoOneTransaction({ + protyle, + selectsElement: [liElement, liElement.nextElementSibling], + type: "BlocksMergeSuperBlock", + level: "row" + }); + } focusByWbr(parentLiItemElement, range); return; }