Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/18168

Vanessa06c5189c0c76
diff --git a/app/src/protyle/wysiwyg/enter.ts b/app/src/protyle/wysiwyg/enter.ts
index 76e1fffd94..da7a28f189 100644
--- a/app/src/protyle/wysiwyg/enter.ts
+++ b/app/src/protyle/wysiwyg/enter.ts
@@ -149,7 +149,7 @@ export const enter = async (blockElement: HTMLElement, range: Range, protyle: IP
parentBlockElement.after(blockElement);
} else {
doInsert.previousID = getPreviousBlockSibling(topElement)?.getAttribute("data-node-id");
- doInsert.parentID = topElement.parentElement.getAttribute("data-node-id") || protyle.block.parentID;
+ doInsert.parentID = getParentBlock(topElement).getAttribute("data-node-id") || protyle.block.parentID;
undoInsert.previousID = doInsert.previousID;
undoInsert.parentID = doInsert.parentID;
topElement.after(blockElement);
diff --git a/app/src/protyle/wysiwyg/input.ts b/app/src/protyle/wysiwyg/input.ts
index dfc4a4c64f..a62429e149 100644
--- a/app/src/protyle/wysiwyg/input.ts
+++ b/app/src/protyle/wysiwyg/input.ts
@@ -8,6 +8,7 @@ import {
fixAdjacentTags,
getContenteditableElement,
getNextBlockSibling,
+ getParentBlock,
getPreviousBlockSibling,
hasNextSibling,
hasPreviousSibling,
@@ -380,7 +381,7 @@ const updateInput = (html: string, protyle: IProtyle, id: string) => {
data: item.outerHTML,
id: tempId,
previousID: index === 0 ? (firstElement ? getPreviousBlockSibling(firstElement)?.getAttribute("data-node-id") : undefined) : item.previousElementSibling.getAttribute("data-node-id"),
- parentID: firstElement?.parentElement.getAttribute("data-node-id") || protyle.block.parentID
+ parentID: firstElement ? (getParentBlock(firstElement).getAttribute("data-node-id") || protyle.block.parentID) : protyle.block.parentID
});
undoOperations.push({
id: tempId,
diff --git a/app/src/protyle/wysiwyg/list.ts b/app/src/protyle/wysiwyg/list.ts
index c59ca3a557..ad81a957ae 100644
--- a/app/src/protyle/wysiwyg/list.ts
+++ b/app/src/protyle/wysiwyg/list.ts
@@ -431,7 +431,7 @@ export const breakList = (protyle: IProtyle, blockElement: Element, range: Range
action: "insert",
data: listItemElement.parentElement.outerHTML,
previousID: getPreviousBlockSibling(listItemElement.parentElement)?.getAttribute("data-node-id"),
- parentID: listItemElement.parentElement.parentElement.getAttribute("data-node-id") || protyle.block.rootID
+ parentID: getParentBlock(listItemElement.parentElement).getAttribute("data-node-id") || protyle.block.rootID
});
listItemElement.parentElement.remove();
doOperations.push({
@@ -878,7 +878,7 @@ export const listOutdent = async (protyle: IProtyle, liItemElements: Element[],
data: parentLiItemElement.outerHTML,
previousID: getPreviousBlockSibling(parentLiItemElement)?.getAttribute("data-node-id"),
// https://github.com/siyuan-note/siyuan/issues/9237 无 previousID
- parentID: parentLiItemElement.parentElement.getAttribute("data-node-id"),
+ parentID: getParentBlock(parentLiItemElement).getAttribute("data-node-id"),
});
parentLiItemElement.remove();
} else if (liElement.childElementCount === 1) {
diff --git a/app/src/protyle/wysiwyg/move.ts b/app/src/protyle/wysiwyg/move.ts
index 76a84eba15..d6180f4f40 100644
--- a/app/src/protyle/wysiwyg/move.ts
+++ b/app/src/protyle/wysiwyg/move.ts
@@ -1,4 +1,4 @@
-import {getNextBlockSibling, getPreviousBlockSibling, getTopAloneElement} from "./getBlock";
+import {getNextBlockSibling, getParentBlock, getPreviousBlockSibling, getTopAloneElement} from "./getBlock";
import {hasClosestByAttribute} from "../util/hasClosest";
import {updateListOrder} from "./list";
import {transaction, updateTransaction} from "./transaction";
@@ -109,7 +109,7 @@ export const moveToUp = (protyle: IProtyle, nodeElement: HTMLElement, range: Ran
action: "move",
id,
previousID: getPreviousBlockSibling(previousElement)?.getAttribute("data-node-id"),
- parentID: previousElement.parentElement.getAttribute("data-node-id") || protyle.block.parentID
+ parentID: getParentBlock(previousElement).getAttribute("data-node-id") || protyle.block.parentID
}]);
sourceElements[sourceElements.length - 1].after(previousElement);
refreshSbResize(sourceElements[0].parentElement);
@@ -209,7 +209,7 @@ export const moveToDown = (protyle: IProtyle, nodeElement: HTMLElement, range: R
action: "move",
id,
previousID: getPreviousBlockSibling(sourceElements[0])?.getAttribute("data-node-id"),
- parentID: nextElement.parentElement.getAttribute("data-node-id") || protyle.block.parentID
+ parentID: getParentBlock(nextElement).getAttribute("data-node-id") || protyle.block.parentID
}], [{
action: "move",
id,
diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.ts
index d99a283587..1a57038f05 100644
--- a/app/src/protyle/wysiwyg/transaction.ts
+++ b/app/src/protyle/wysiwyg/transaction.ts
@@ -4,6 +4,7 @@ import {
getContenteditableElement,
getFirstBlock,
getNextBlockSibling,
+ getParentBlock,
getPreviousBlockSibling,
getSbChildBlockCount,
getTopAloneElement
@@ -1103,7 +1104,7 @@ export const turnsIntoOneTransaction = async (options: {
parentElement.innerHTML = html + '<div class="protyle-attr" contenteditable="false"></div>';
}
const previousId = options.selectsElement[0].getAttribute("data-node-id");
- const parentId = options.selectsElement[0].parentElement.getAttribute("data-node-id") || options.protyle.block.parentID;
+ const parentId = getParentBlock(options.selectsElement[0]).getAttribute("data-node-id") || options.protyle.block.parentID;
const doOperations: IOperation[] = [{
action: "insert",
id,
@@ -1271,7 +1272,7 @@ export const turnsIntoTransaction = (options: {
id,
previousID: previousId || getPreviousBlockSibling(item)?.getAttribute("data-node-id"),
data: item.outerHTML,
- parentID: item.parentElement?.getAttribute("data-node-id") || options.protyle.block.parentID || options.protyle.block.rootID,
+ parentID: getParentBlock(item)?.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");
@@ -1280,7 +1281,7 @@ export const turnsIntoTransaction = (options: {
id: tempItemId,
previousID: tempItem.previousElementSibling?.getAttribute("data-node-id") || getPreviousBlockSibling(item)?.getAttribute("data-node-id"),
data: tempItem.outerHTML,
- parentID: item.parentElement?.getAttribute("data-node-id") || options.protyle.block.parentID || options.protyle.block.rootID,
+ parentID: getParentBlock(item)?.getAttribute("data-node-id") || options.protyle.block.parentID || options.protyle.block.rootID,
});
undoOperations.splice(0, 0, {
action: "delete",
@@ -1331,7 +1332,7 @@ export const turnsIntoTransaction = (options: {
id,
previousID: doOperations[doOperations.length - 1]?.id || getPreviousBlockSibling(item)?.getAttribute("data-node-id"),
data: item.outerHTML,
- parentID: item.parentElement?.getAttribute("data-node-id") || options.protyle.block.parentID || options.protyle.block.rootID,
+ parentID: getParentBlock(item)?.getAttribute("data-node-id") || options.protyle.block.parentID || options.protyle.block.rootID,
});
doOperations.push({
action: "delete",
@@ -1348,7 +1349,7 @@ export const turnsIntoTransaction = (options: {
id: tempItemId,
previousID: tempItem.previousElementSibling?.getAttribute("data-node-id") || getPreviousBlockSibling(item)?.getAttribute("data-node-id"),
data: tempItem.outerHTML,
- parentID: item.parentElement?.getAttribute("data-node-id") || options.protyle.block.parentID || options.protyle.block.rootID,
+ parentID: getParentBlock(item)?.getAttribute("data-node-id") || options.protyle.block.parentID || options.protyle.block.rootID,
});
undoOperations.splice(0, 0, {
action: "delete",
@@ -1422,7 +1423,7 @@ export const turnsOneInto = async (options: {
});
previousId = response.data.previousID;
}
- const parentId = options.nodeElement.parentElement.getAttribute("data-node-id") || options.protyle.block.parentID;
+ const parentId = getParentBlock(options.nodeElement).getAttribute("data-node-id") || options.protyle.block.parentID;
// @ts-ignore
const newHTML = options.protyle.lute[options.type](options.nodeElement.outerHTML, options.level);
options.nodeElement.insertAdjacentHTML("afterend", newHTML);