mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-03 19:29:32 +08:00
This commit is contained in:
parent
be20a4fca1
commit
67cf800d96
@ -1036,7 +1036,7 @@ export const turnsIntoTransaction = (options: {
|
|||||||
let html = "";
|
let html = "";
|
||||||
const doOperations: IOperation[] = [];
|
const doOperations: IOperation[] = [];
|
||||||
const undoOperations: IOperation[] = [];
|
const undoOperations: IOperation[] = [];
|
||||||
const tempElement = document.createElement("div");
|
let previousId: string;
|
||||||
selectsElement.forEach((item, index) => {
|
selectsElement.forEach((item, index) => {
|
||||||
if ((options.type === "Blocks2Ps" || options.type === "Blocks2Hs") &&
|
if ((options.type === "Blocks2Ps" || options.type === "Blocks2Hs") &&
|
||||||
item.getAttribute("data-type") === "NodeHeading" && item.getAttribute("fold") === "1") {
|
item.getAttribute("data-type") === "NodeHeading" && item.getAttribute("fold") === "1") {
|
||||||
@ -1047,64 +1047,91 @@ export const turnsIntoTransaction = (options: {
|
|||||||
item.removeAttribute("select-end");
|
item.removeAttribute("select-end");
|
||||||
html += item.outerHTML;
|
html += item.outerHTML;
|
||||||
const id = item.getAttribute("data-node-id");
|
const id = item.getAttribute("data-node-id");
|
||||||
undoOperations.push({
|
|
||||||
action: "update",
|
|
||||||
id,
|
|
||||||
data: item.outerHTML,
|
|
||||||
parentID: item.parentElement?.getAttribute("data-node-id") || options.protyle.block.parentID || options.protyle.block.rootID,
|
|
||||||
previousID: undoOperations[undoOperations.length - 1]?.id || item.previousElementSibling?.getAttribute("data-node-id")
|
|
||||||
});
|
|
||||||
|
|
||||||
|
const tempElement = document.createElement("template");
|
||||||
if (!options.isContinue) {
|
if (!options.isContinue) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
item.outerHTML = options.protyle.lute[options.type](item.outerHTML, options.level);
|
const newHTML = options.protyle.lute[options.type](item.outerHTML, options.level);
|
||||||
} else {
|
tempElement.innerHTML = newHTML;
|
||||||
if (index === selectsElement.length - 1) {
|
|
||||||
// @ts-ignore
|
if (!tempElement.content.querySelector(`[data-node-id="${id}"]`)) {
|
||||||
tempElement.innerHTML = options.protyle.lute[options.type](html, options.level);
|
undoOperations.push({
|
||||||
item.outerHTML = tempElement.innerHTML;
|
action: "insert",
|
||||||
|
id,
|
||||||
|
previousID: previousId || item.previousElementSibling?.getAttribute("data-node-id"),
|
||||||
|
data: item.outerHTML,
|
||||||
|
parentID: item.parentElement?.getAttribute("data-node-id") || options.protyle.block.parentID || options.protyle.block.rootID,
|
||||||
|
});
|
||||||
|
Array.from(tempElement.content.children).forEach((tempItem: HTMLElement) => {
|
||||||
|
const tempItemId = tempItem.getAttribute("data-node-id");
|
||||||
|
doOperations.push({
|
||||||
|
action: "insert",
|
||||||
|
id: tempItemId,
|
||||||
|
previousID: tempItem.previousElementSibling?.getAttribute("data-node-id") || item.previousElementSibling?.getAttribute("data-node-id"),
|
||||||
|
data: tempItem.outerHTML,
|
||||||
|
parentID: item.parentElement?.getAttribute("data-node-id") || options.protyle.block.parentID || options.protyle.block.rootID,
|
||||||
|
});
|
||||||
|
undoOperations.splice(0, 0, {
|
||||||
|
action: "delete",
|
||||||
|
id: tempItemId,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
doOperations.push({
|
||||||
|
action: "delete",
|
||||||
|
id,
|
||||||
|
});
|
||||||
|
if (item.isSameNode(selectsElement[index + 1]?.previousElementSibling)) {
|
||||||
|
previousId = id;
|
||||||
|
} else {
|
||||||
|
previousId = undefined;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
item.remove();
|
undoOperations.push({
|
||||||
|
action: "update",
|
||||||
|
id,
|
||||||
|
data: item.outerHTML,
|
||||||
|
});
|
||||||
|
doOperations.push({
|
||||||
|
action: "update",
|
||||||
|
id: item.id,
|
||||||
|
data: newHTML
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
item.outerHTML = newHTML;
|
||||||
});
|
|
||||||
undoOperations.forEach(item => {
|
|
||||||
const nodeElement = options.protyle.wysiwyg.element.querySelector(`[data-node-id="${item.id}"]`);
|
|
||||||
if (!nodeElement) {
|
|
||||||
item.action = "insert";
|
|
||||||
doOperations.push({
|
|
||||||
action: "delete",
|
|
||||||
id: item.id,
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
doOperations.push({
|
undoOperations.push({
|
||||||
action: "update",
|
|
||||||
id: item.id,
|
|
||||||
data: nodeElement.outerHTML
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Array.from(tempElement.children).forEach(item => {
|
|
||||||
const itemId = item.getAttribute("data-node-id");
|
|
||||||
let find = false;
|
|
||||||
undoOperations.find(undoItem => {
|
|
||||||
if (itemId === undoItem.id) {
|
|
||||||
find = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (!find) {
|
|
||||||
doOperations.push({
|
|
||||||
action: "insert",
|
action: "insert",
|
||||||
id: itemId,
|
id,
|
||||||
previousID: item.previousElementSibling?.getAttribute("data-node-id") || undoOperations[0].previousID,
|
previousID: doOperations[doOperations.length - 1]?.id || item.previousElementSibling?.getAttribute("data-node-id"),
|
||||||
data: item.outerHTML,
|
data: item.outerHTML,
|
||||||
parentID: item.parentElement?.getAttribute("data-node-id") || options.protyle.block.parentID || options.protyle.block.rootID,
|
parentID: item.parentElement?.getAttribute("data-node-id") || options.protyle.block.parentID || options.protyle.block.rootID,
|
||||||
});
|
});
|
||||||
undoOperations.splice(0, 0, {
|
doOperations.push({
|
||||||
action: "delete",
|
action: "delete",
|
||||||
id: itemId,
|
id,
|
||||||
});
|
});
|
||||||
|
if (index === selectsElement.length - 1) {
|
||||||
|
// @ts-ignore
|
||||||
|
const newHTML = options.protyle.lute[options.type](html, options.level);
|
||||||
|
tempElement.innerHTML = newHTML;
|
||||||
|
Array.from(tempElement.content.children).forEach((tempItem: HTMLElement) => {
|
||||||
|
const tempItemId = tempItem.getAttribute("data-node-id");
|
||||||
|
doOperations.push({
|
||||||
|
action: "insert",
|
||||||
|
id: tempItemId,
|
||||||
|
previousID: tempItem.previousElementSibling?.getAttribute("data-node-id") || item.previousElementSibling?.getAttribute("data-node-id"),
|
||||||
|
data: tempItem.outerHTML,
|
||||||
|
parentID: item.parentElement?.getAttribute("data-node-id") || options.protyle.block.parentID || options.protyle.block.rootID,
|
||||||
|
});
|
||||||
|
undoOperations.splice(0, 0, {
|
||||||
|
action: "delete",
|
||||||
|
id: tempItemId,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
item.outerHTML = newHTML;
|
||||||
|
} else {
|
||||||
|
item.remove();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
transaction(options.protyle, doOperations, undoOperations);
|
transaction(options.protyle, doOperations, undoOperations);
|
||||||
|
Loading…
Reference in New Issue
Block a user