Vanessa 2025-09-06 22:33:31 +08:00
parent 4e4398ef47
commit 468b670bcc
3 changed files with 25 additions and 25 deletions

View File

@ -1798,7 +1798,6 @@ export class WYSIWYG {
needClipboardWrite = true;
const response = await fetchSyncPost("/api/block/getHeadingChildrenDOM", {id: item.getAttribute("data-node-id")});
html += response.data;
setFold(protyle, topElement, undefined, true);
} else {
html += removeEmbed(topElement);
}

View File

@ -23,6 +23,7 @@ import {hasClosestByClassName} from "../util/hasClosest";
import {getInstanceById} from "../../layout/util";
import {Tab} from "../../layout/Tab";
import {Backlink} from "../../layout/dock/Backlink";
import {fetchSyncPost} from "../../util/fetch";
export const removeBlock = async (protyle: IProtyle, blockElement: Element, range: Range, type: "Delete" | "Backspace" | "remove") => {
protyle.observerLoad?.disconnect();
@ -32,7 +33,7 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang
if (selectElements?.length > 0) {
const deletes: IOperation[] = [];
const inserts: IOperation[] = [];
let sideElement;
let sideElement: Element | boolean;
let sideIsNext = false;
if (type === "Backspace") {
sideElement = selectElements[0].previousElementSibling;
@ -52,7 +53,8 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang
let topParentElement: Element;
hideElements(["select"], protyle);
let foldPreviousId: string;
selectElements.find((item: HTMLElement) => {
for (let i = 0; i < selectElements.length; i++) {
const item = selectElements[i];
const topElement = getTopAloneElement(item);
topParentElement = topElement.parentElement;
const id = topElement.getAttribute("data-node-id");
@ -79,19 +81,23 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang
sideIsNext = false;
}
if (topElement.getAttribute("data-type") === "NodeHeading" && topElement.getAttribute("fold") === "1") {
// https://github.com/siyuan-note/siyuan/issues/2188
setFold(protyle, topElement, undefined, true);
const foldTransaction = await fetchSyncPost("/api/block/getHeadingDeleteTransaction", {
id: topElement.getAttribute("data-node-id"),
});
deletes.push(...foldTransaction.data.doOperations.slice(1));
let previousID = topElement.previousElementSibling ? topElement.previousElementSibling.getAttribute("data-node-id") : "";
if (typeof foldPreviousId !== "undefined") {
previousID = foldPreviousId;
}
inserts.push({
action: "insert",
data: topElement.outerHTML,
id,
previousID: previousID,
parentID: topElement.parentElement.getAttribute("data-node-id") || protyle.block.parentID
foldTransaction.data.undoOperations.forEach((operationItem: IOperation, index: number) => {
operationItem.previousID = previousID;
if (index > 0) {
operationItem.context = {
ignoreProcess: "true"
};
}
});
inserts.push(...foldTransaction.data.undoOperations);
// 折叠块和非折叠块同时删除时撤销异常 https://github.com/siyuan-note/siyuan/issues/11312
let foldPreviousElement = getPreviousBlock(topElement);
while (foldPreviousElement && foldPreviousElement.childElementCount === 3) {
@ -102,17 +108,9 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang
} else {
foldPreviousId = "";
}
// https://github.com/siyuan-note/siyuan/issues/4422
// // https://github.com/siyuan-note/siyuan/issues/4422
topElement.firstElementChild.removeAttribute("contenteditable");
// 在折叠标题后输入文字,然后全选删除再撤销会重建索引。因此不能删除折叠标题后新输入的输入折叠标题下的内容
const nextElement = topElement.nextElementSibling;
if (nextElement) {
const nextType = nextElement.getAttribute("data-type");
if (nextType !== "NodeHeading" ||
(nextType === "NodeHeading" && nextElement.getAttribute("data-subtype") > topElement.getAttribute("data-subtype"))) {
return true;
}
}
topElement.remove();
} else {
let data = topElement.outerHTML; // 不能 spin ,否则 li 会变为 list
if (topElement.classList.contains("render-node") || topElement.querySelector("div.render-node")) {
@ -136,7 +134,7 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang
}
topElement.remove();
}
});
}
if (sideElement) {
if (protyle.block.showAll && sideElement.classList.contains("protyle-wysiwyg") && protyle.wysiwyg.element.childElementCount === 0) {
setTimeout(() => {
@ -164,11 +162,11 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang
// https://github.com/siyuan-note/siyuan/issues/10389
// https://github.com/siyuan-note/siyuan/issues/10899
if (type !== "Backspace" && sideIsNext) {
focusBlock(sideElement);
focusBlock(sideElement as Element);
} else {
focusBlock(sideElement, undefined, false);
focusBlock(sideElement as Element, undefined, false);
}
scrollCenter(protyle, sideElement);
scrollCenter(protyle, sideElement as Element);
if (listElement) {
inserts.push({
action: "update",

View File

@ -754,6 +754,9 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, isUndo:
return;
}
if (operation.action === "insert") {
if (operation.context?.ignoreProcess === "true") {
return;
}
const cursorElements = [];
if (operation.previousID) {
const previousElement = protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.previousID}"]`);