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

Vanessa42e709620794
diff --git a/app/src/block/util.ts b/app/src/block/util.ts
index 230f15ece6..27cf1cb5d6 100644
--- a/app/src/block/util.ts
+++ b/app/src/block/util.ts
@@ -1,6 +1,11 @@
import {focusByWbr, getEditorRange} from "../protyle/util/selection";
import {hasClosestBlock, hasClosestByClassName} from "../protyle/util/hasClosest";
-import {getContenteditableElement, getParentBlock, getTopAloneElement} from "../protyle/wysiwyg/getBlock";
+import {
+ getContenteditableElement,
+ getParentBlock,
+ getPreviousBlockSibling,
+ getTopAloneElement
+} from "../protyle/wysiwyg/getBlock";
import {genListItemElement, updateListOrder} from "../protyle/wysiwyg/list";
import {transaction, turnsIntoOneTransaction, updateTransaction} from "../protyle/wysiwyg/transaction";
import {scrollCenter} from "../util/highlightById";
@@ -15,7 +20,7 @@ import {mathRender} from "../protyle/render/mathRender";
export const cancelSB = async (protyle: IProtyle, nodeElement: Element, range?: Range) => {
const doOperations: IOperation[] = [];
const undoOperations: IOperation[] = [];
- let previousId = nodeElement.previousElementSibling ? nodeElement.previousElementSibling.getAttribute("data-node-id") : undefined;
+ let previousId = getPreviousBlockSibling(nodeElement)?.getAttribute("data-node-id");
nodeElement.classList.remove("protyle-wysiwyg--select");
nodeElement.removeAttribute("select-start");
nodeElement.removeAttribute("select-end");
@@ -70,7 +75,7 @@ export const cancelSB = async (protyle: IProtyle, nodeElement: Element, range?:
undoOperations.push({
action: "move",
id: item.getAttribute("data-node-id"),
- previousID: item.previousElementSibling ? item.previousElementSibling.getAttribute("data-node-id") : undefined,
+ previousID: getPreviousBlockSibling(item)?.getAttribute("data-node-id"),
parentID: id
});
previousId = item.getAttribute("data-node-id");
@@ -232,13 +237,14 @@ export const insertEmptyBlock = async (protyle: IProtyle, position: InsertPositi
protyle.observerLoad?.disconnect();
let newElement = genEmptyElement(false, true);
let orderIndex = 1;
+ const previousBlockElement = getPreviousBlockSibling(blockElement);
if (blockElement.getAttribute("data-type") === "NodeListItem") {
newElement = genListItemElement(blockElement, 0, true) as HTMLDivElement;
orderIndex = parseInt(blockElement.parentElement.firstElementChild.getAttribute("data-marker"));
- } else if (position === "beforebegin" && blockElement.previousElementSibling &&
- blockElement.previousElementSibling.getAttribute("data-type") === "NodeHeading" &&
- blockElement.previousElementSibling.getAttribute("fold") === "1") {
- newElement = genHeadingElement(blockElement.previousElementSibling, false, true) as HTMLDivElement;
+ } else if (position === "beforebegin" &&
+ previousBlockElement?.getAttribute("data-type") === "NodeHeading" &&
+ previousBlockElement.getAttribute("fold") === "1") {
+ newElement = genHeadingElement(previousBlockElement, false, true) as HTMLDivElement;
} else if (position === "afterend" && blockElement &&
blockElement.getAttribute("data-type") === "NodeHeading" &&
blockElement.getAttribute("fold") === "1") {
diff --git a/app/src/protyle/util/editorCommonEvent.ts b/app/src/protyle/util/editorCommonEvent.ts
index 8e3138a119..94d7a6b731 100644
--- a/app/src/protyle/util/editorCommonEvent.ts
+++ b/app/src/protyle/util/editorCommonEvent.ts
@@ -1,6 +1,7 @@
import {focusBlock, focusByRange, getRangeByPoint} from "./selection";
import {
getContenteditableElement,
+ getNextBlockSibling,
getParentBlock,
getPreviousBlockSibling,
getSbChildBlockCount,
@@ -268,7 +269,7 @@ const moveTo = async (protyle: IProtyle, sourceElements: Element[], targetElemen
action: "insert",
data: topSourceElement.outerHTML,
id: topSourceElement.getAttribute("data-node-id"),
- previousID: topSourceElement.previousElementSibling?.getAttribute("data-node-id"),
+ previousID: getPreviousBlockSibling(topSourceElement)?.getAttribute("data-node-id"),
parentID: getParentBlock(topSourceElement)?.getAttribute("data-node-id") || protyle.block.parentID || protyle.block.rootID
});
const topSourceParentElement = topSourceElement.parentElement;
@@ -482,8 +483,8 @@ const dragSb = async (protyle: IProtyle, sourceElements: Element[], targetElemen
action: "insert",
data: sbElement.outerHTML,
id: sbElement.getAttribute("data-node-id"),
- nextID: sbElement.nextElementSibling?.getAttribute("data-node-id"),
- previousID: sbElement.previousElementSibling?.getAttribute("data-node-id"),
+ nextID: getNextBlockSibling(sbElement)?.getAttribute("data-node-id"),
+ previousID: getPreviousBlockSibling(sbElement)?.getAttribute("data-node-id"),
parentID: getParentBlock(sbElement)?.getAttribute("data-node-id") || protyle.block.parentID || protyle.block.rootID
}];
// 临时插入,防止后面计算错误,最终再移动矫正
@@ -528,10 +529,11 @@ const dragSb = async (protyle: IProtyle, sourceElements: Element[], targetElemen
});
const foldElements: Element[] = [];
newSourceParentElement.forEach(item => {
+ const nextBlockElement = getNextBlockSibling(item);
if (item.getAttribute("data-type") === "NodeHeading" && item.getAttribute("fold") === "1" &&
- item.nextElementSibling && (
- item.nextElementSibling.getAttribute("data-type") !== "NodeHeading" ||
- (item.nextElementSibling.getAttribute("data-subtype") || "") > item.getAttribute("data-subtype")
+ nextBlockElement && (
+ nextBlockElement.getAttribute("data-type") !== "NodeHeading" ||
+ (nextBlockElement.getAttribute("data-subtype") || "") > item.getAttribute("data-subtype")
)) {
foldElements.push(item);
}
@@ -584,14 +586,15 @@ const dragSame = async (protyle: IProtyle, sourceElements: Element[], targetElem
undoOperations.push(...moveToResult.undoOperations);
const newSourceParentElement = moveToResult.newSourceElements;
let foldData;
+ const previousBlockElement = getPreviousBlockSibling(targetElement);
if (isBottom &&
targetElement.getAttribute("data-type") === "NodeHeading" &&
targetElement.getAttribute("fold") === "1") {
foldData = setFold(protyle, targetElement, true, false, false, true);
- } else if (!isBottom && targetElement.previousElementSibling &&
- targetElement.previousElementSibling.getAttribute("data-type") === "NodeHeading" &&
- targetElement.previousElementSibling.getAttribute("fold") === "1") {
- foldData = setFold(protyle, targetElement.previousElementSibling, true, false, false, true);
+ } else if (!isBottom &&
+ previousBlockElement?.getAttribute("data-type") === "NodeHeading" &&
+ previousBlockElement.getAttribute("fold") === "1") {
+ foldData = setFold(protyle, previousBlockElement, true, false, false, true);
}
if (foldData) {
foldData.doOperations[0].context = {
@@ -629,9 +632,10 @@ const dragSame = async (protyle: IProtyle, sourceElements: Element[], targetElem
newSourceParentElement.forEach(item => {
if (item.getAttribute("data-type") === "NodeHeading" && item.getAttribute("fold") === "1") {
hasFoldHeading = true;
- if (item.nextElementSibling && (
- item.nextElementSibling.getAttribute("data-type") !== "NodeHeading" ||
- item.nextElementSibling.getAttribute("data-subtype") > item.getAttribute("data-subtype")
+ const nextBlockElement = getNextBlockSibling(item);
+ if (nextBlockElement && (
+ nextBlockElement.getAttribute("data-type") !== "NodeHeading" ||
+ nextBlockElement.getAttribute("data-subtype") > item.getAttribute("data-subtype")
)) {
const foldOperations = setFold(protyle, item, true, false, false, true);
doOperations.push(...foldOperations.doOperations);
@@ -1755,7 +1759,7 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
if (targetElement && (targetElement.classList.contains("bq") || targetElement.classList.contains("sb") || targetElement.classList.contains("list") || targetElement.classList.contains("li"))) {
let prevElement = hasClosestBlock(document.elementFromPoint(point.x, point.y - 6));
while (prevElement && targetElement.contains(prevElement)) {
- if (prevElement.nextElementSibling?.getAttribute("data-node-id")) {
+ if (getNextBlockSibling(prevElement)) {
targetElement = prevElement;
}
prevElement = prevElement.parentElement;
diff --git a/app/src/protyle/util/insertHTML.ts b/app/src/protyle/util/insertHTML.ts
index 8e44be3af5..5ab26925f7 100644
--- a/app/src/protyle/util/insertHTML.ts
+++ b/app/src/protyle/util/insertHTML.ts
@@ -1,7 +1,7 @@
import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName, hasClosestByTag} from "./hasClosest";
import * as dayjs from "dayjs";
import {transaction, updateTransaction} from "../wysiwyg/transaction";
-import {getContenteditableElement, getParentBlock, fixAdjacentTags} from "../wysiwyg/getBlock";
+import {fixAdjacentTags, getContenteditableElement, getParentBlock, getPreviousBlockSibling} from "../wysiwyg/getBlock";
import {
fixTableRange,
focusBlock,
@@ -668,7 +668,7 @@ export const insertHTML = (html: string, protyle: IProtyle, isBlock = false,
action: "insert",
data: oldHTML,
id,
- previousID: blockElement.previousElementSibling ? blockElement.previousElementSibling.getAttribute("data-node-id") : "",
+ previousID: getPreviousBlockSibling(blockElement)?.getAttribute("data-node-id") || "",
parentID: getParentBlock(blockElement).getAttribute("data-node-id") || protyle.block.parentID
});
blockElement.remove();
diff --git a/app/src/protyle/wysiwyg/enter.ts b/app/src/protyle/wysiwyg/enter.ts
index 140a5d45f2..76e1fffd94 100644
--- a/app/src/protyle/wysiwyg/enter.ts
+++ b/app/src/protyle/wysiwyg/enter.ts
@@ -2,6 +2,7 @@ import {genEmptyElement, genHeadingElement, insertEmptyBlock} from "../../block/
import {focusByRange, focusByWbr, getSelectionOffset, setLastNodeRange} from "../util/selection";
import {
getContenteditableElement, getParentBlock,
+ getPreviousBlockSibling,
getTopEmptyElement,
hasNextSibling,
hasPreviousSibling,
@@ -147,7 +148,7 @@ export const enter = async (blockElement: HTMLElement, range: Range, protyle: IP
undoInsert.previousID = blockElement.previousElementSibling.getAttribute("data-node-id");
parentBlockElement.after(blockElement);
} else {
- doInsert.previousID = topElement.previousElementSibling ? topElement.previousElementSibling.getAttribute("data-node-id") : undefined;
+ doInsert.previousID = getPreviousBlockSibling(topElement)?.getAttribute("data-node-id");
doInsert.parentID = topElement.parentElement.getAttribute("data-node-id") || protyle.block.parentID;
undoInsert.previousID = doInsert.previousID;
undoInsert.parentID = doInsert.parentID;
@@ -197,10 +198,10 @@ export const enter = async (blockElement: HTMLElement, range: Range, protyle: IP
// 段首换行
if (editableElement.textContent !== "" && range.toString() === "" && position.start === 0) {
let newElement;
- if (blockElement.previousElementSibling &&
- blockElement.previousElementSibling.getAttribute("data-type") === "NodeHeading" &&
- blockElement.previousElementSibling.getAttribute("fold") === "1") {
- newElement = genHeadingElement(blockElement.previousElementSibling, false, true) as HTMLDivElement;
+ const previousBlockElement = getPreviousBlockSibling(blockElement);
+ if (previousBlockElement?.getAttribute("data-type") === "NodeHeading" &&
+ previousBlockElement.getAttribute("fold") === "1") {
+ newElement = genHeadingElement(previousBlockElement, false, true) as HTMLDivElement;
} else {
newElement = genEmptyElement(false, true);
}
diff --git a/app/src/protyle/wysiwyg/getBlock.ts b/app/src/protyle/wysiwyg/getBlock.ts
index 4ba37f3236..346c29f13d 100644
--- a/app/src/protyle/wysiwyg/getBlock.ts
+++ b/app/src/protyle/wysiwyg/getBlock.ts
@@ -173,8 +173,7 @@ export const getTopEmptyElement = (element: Element) => {
return true;
}
});
- if (hasText || topElement.previousElementSibling?.getAttribute("data-node-id") ||
- topElement.nextElementSibling?.getAttribute("data-node-id")) {
+ if (hasText || getPreviousBlockSibling(topElement) || getNextBlockSibling(topElement)) {
break;
} else {
topElement = topElement.parentElement;
diff --git a/app/src/protyle/wysiwyg/input.ts b/app/src/protyle/wysiwyg/input.ts
index d4adece94c..dfc4a4c64f 100644
--- a/app/src/protyle/wysiwyg/input.ts
+++ b/app/src/protyle/wysiwyg/input.ts
@@ -4,7 +4,15 @@ import * as dayjs from "dayjs";
import {transaction, updateTransaction} from "./transaction";
import {mathRender} from "../render/mathRender";
import {highlightRender} from "../render/highlightRender";
-import {getContenteditableElement, fixAdjacentTags, hasNextSibling, hasPreviousSibling, isNotEditBlock} from "./getBlock";
+import {
+ fixAdjacentTags,
+ getContenteditableElement,
+ getNextBlockSibling,
+ getPreviousBlockSibling,
+ hasNextSibling,
+ hasPreviousSibling,
+ isNotEditBlock
+} from "./getBlock";
import {genEmptyBlock} from "../../block/util";
import {blockRender} from "../render/blockRender";
import {hideElements} from "../ui/hideElements";
@@ -153,8 +161,8 @@ export const input = async (protyle: IProtyle, blockElement: HTMLElement, range:
if (["---", "___", "***"].includes(editElement.textContent) && type !== "NodeCodeBlock") {
html = `<div data-node-id="${id}" data-type="NodeThematicBreak" class="hr"><div></div></div>`;
// https://github.com/siyuan-note/siyuan/issues/12593
- const nextBlockElement = blockElement.nextElementSibling;
- if (nextBlockElement && nextBlockElement.getAttribute("data-node-id")) {
+ const nextBlockElement = getNextBlockSibling(blockElement);
+ if (nextBlockElement) {
if (!isNotEditBlock(nextBlockElement)) {
focusBlock(nextBlockElement);
} else {
@@ -371,7 +379,7 @@ const updateInput = (html: string, protyle: IProtyle, id: string) => {
action: "insert",
data: item.outerHTML,
id: tempId,
- previousID: index === 0 ? firstElement?.previousElementSibling?.getAttribute("data-node-id") : item.previousElementSibling.getAttribute("data-node-id"),
+ 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
});
undoOperations.push({
diff --git a/app/src/protyle/wysiwyg/list.ts b/app/src/protyle/wysiwyg/list.ts
index ab09d889ee..c59ca3a557 100644
--- a/app/src/protyle/wysiwyg/list.ts
+++ b/app/src/protyle/wysiwyg/list.ts
@@ -5,7 +5,7 @@ import * as dayjs from "dayjs";
import {Constants} from "../../constants";
import {moveToPrevious, removeBlock} from "./remove";
import {hasClosestByClassName, isBlockElement} from "../util/hasClosest";
-import {getParentBlock} from "./getBlock";
+import {getParentBlock, getPreviousBlockSibling} from "./getBlock";
import {setFold} from "../util/blockFold";
import {scrollCenter} from "../../util/highlightById";
@@ -430,7 +430,7 @@ export const breakList = (protyle: IProtyle, blockElement: Element, range: Range
id: parentId,
action: "insert",
data: listItemElement.parentElement.outerHTML,
- previousID: listItemElement.parentElement.previousElementSibling?.getAttribute("data-node-id"),
+ previousID: getPreviousBlockSibling(listItemElement.parentElement)?.getAttribute("data-node-id"),
parentID: listItemElement.parentElement.parentElement.getAttribute("data-node-id") || protyle.block.rootID
});
listItemElement.parentElement.remove();
@@ -443,7 +443,7 @@ export const breakList = (protyle: IProtyle, blockElement: Element, range: Range
id: listItemId,
action: "insert",
data: listItemElement.outerHTML,
- previousID: listItemElement.previousElementSibling?.getAttribute("data-node-id"),
+ previousID: getPreviousBlockSibling(listItemElement)?.getAttribute("data-node-id"),
parentID: parentId
});
listItemElement.remove();
@@ -565,7 +565,7 @@ export const listOutdent = async (protyle: IProtyle, liItemElements: Element[],
action: "move",
id: nextElement.getAttribute("data-node-id"),
parentID: lastBlockElement.getAttribute("data-node-id"),
- previousID: topOldPreviousID || nextElement.previousElementSibling?.getAttribute("data-node-id"),
+ previousID: topOldPreviousID || getPreviousBlockSibling(nextElement)?.getAttribute("data-node-id"),
});
topOldPreviousID = nextElement.getAttribute("data-node-id");
const tempElement = nextElement;
@@ -621,7 +621,7 @@ export const listOutdent = async (protyle: IProtyle, liItemElements: Element[],
action: "insert",
data: movedHTML,
id: liId,
- previousID: liElement.previousElementSibling?.getAttribute("data-node-id"),
+ previousID: getPreviousBlockSibling(liElement)?.getAttribute("data-node-id"),
parentID: parentLiItemElement.getAttribute("data-node-id") || protyle.block.parentID
});
liElement.remove();
@@ -678,7 +678,7 @@ export const listOutdent = async (protyle: IProtyle, liItemElements: Element[],
range.insertNode(document.createElement("wbr"));
const doOperations: IOperation[] = [];
const undoOperations: IOperation[] = [];
- const previousID = liItemElements[0].previousElementSibling?.getAttribute("data-node-id");
+ const previousID = getPreviousBlockSibling(liItemElements[0])?.getAttribute("data-node-id");
let startIndex;
if (!liItemElements[0].previousElementSibling && liElement.getAttribute("data-subtype") === "o") {
startIndex = parseInt(liItemElements[0].getAttribute("data-marker"));
@@ -876,7 +876,7 @@ export const listOutdent = async (protyle: IProtyle, liItemElements: Element[],
action: "insert",
id: parentLiItemElement.getAttribute("data-node-id"),
data: parentLiItemElement.outerHTML,
- previousID: parentLiItemElement.previousElementSibling?.getAttribute("data-node-id"),
+ previousID: getPreviousBlockSibling(parentLiItemElement)?.getAttribute("data-node-id"),
// https://github.com/siyuan-note/siyuan/issues/9237 无 previousID
parentID: parentLiItemElement.parentElement.getAttribute("data-node-id"),
});
@@ -890,7 +890,7 @@ export const listOutdent = async (protyle: IProtyle, liItemElements: Element[],
action: "insert",
id: liElement.getAttribute("data-node-id"),
data: liElement.outerHTML,
- previousID: liElement.previousElementSibling.getAttribute("data-node-id")
+ previousID: getPreviousBlockSibling(liElement)?.getAttribute("data-node-id")
});
liElement.remove();
} else if (liElement.getAttribute("data-subtype") === "o") {
diff --git a/app/src/protyle/wysiwyg/remove.ts b/app/src/protyle/wysiwyg/remove.ts
index 0a2ef11ebe..1abdfff9cc 100644
--- a/app/src/protyle/wysiwyg/remove.ts
+++ b/app/src/protyle/wysiwyg/remove.ts
@@ -441,10 +441,10 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang
return;
}
if (blockType === "NodeHeading") {
- if (blockElement.previousElementSibling &&
- blockElement.previousElementSibling.getAttribute("data-type") === "NodeHeading" &&
- blockElement.previousElementSibling.getAttribute("fold") === "1") {
- setFold(protyle, blockElement.previousElementSibling, true, false, false);
+ const previousBlockElement = getPreviousBlockSibling(blockElement);
+ if (previousBlockElement?.getAttribute("data-type") === "NodeHeading" &&
+ previousBlockElement.getAttribute("fold") === "1") {
+ setFold(protyle, previousBlockElement, true, false, false);
}
if (blockType === "NodeHeading" &&
blockElement.getAttribute("fold") === "1") {
@@ -761,7 +761,7 @@ const removeLi = async (protyle: IProtyle, blockElement: Element, range: Range,
action: "insert",
id: item.getAttribute("data-node-id"),
data: item.outerHTML,
- previousID: index === 0 ? listElement.previousElementSibling?.getAttribute("data-node-id") : doOperations[index - 1].id,
+ previousID: index === 0 ? getPreviousBlockSibling(listElement)?.getAttribute("data-node-id") : doOperations[index - 1].id,
parentID: getParentBlock(listElement).getAttribute("data-node-id") || protyle.block.parentID
});
undoOperations.push({
diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.ts
index 16f84a3ad0..d99a283587 100644
--- a/app/src/protyle/wysiwyg/transaction.ts
+++ b/app/src/protyle/wysiwyg/transaction.ts
@@ -1,6 +1,13 @@
import {fetchPost, fetchSyncPost} from "../../util/fetch";
import {focusBlock, focusByWbr, focusSideBlock, getEditorRange} from "../util/selection";
-import {getContenteditableElement, getFirstBlock, getSbChildBlockCount, getTopAloneElement} from "./getBlock";
+import {
+ getContenteditableElement,
+ getFirstBlock,
+ getNextBlockSibling,
+ getPreviousBlockSibling,
+ getSbChildBlockCount,
+ getTopAloneElement
+} from "./getBlock";
import {Constants} from "../../constants";
import {blockRender} from "../render/blockRender";
import {processRender} from "../util/processCode";
@@ -178,7 +185,7 @@ const promiseTransaction = (options: {
let hasFind = false;
if (operation.previousID && updateElements.length > 0) {
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.previousID}"]`)).forEach(item => {
- if (!isInEmbedBlock(item) && !item.nextElementSibling.contains(range.startContainer)) {
+ if (!isInEmbedBlock(item) && !getNextBlockSibling(item)?.contains(range.startContainer)) {
item.after(processClonePHElement(updateElements[0].cloneNode(true) as Element));
hasFind = true;
}
@@ -230,7 +237,7 @@ const promiseTransaction = (options: {
const cursorElements: Element[] = [];
if (operation.previousID) {
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.previousID}"]`)).forEach(item => {
- if (item.nextElementSibling?.getAttribute("data-node-id") !== operation.id &&
+ if (getNextBlockSibling(item)?.getAttribute("data-node-id") !== operation.id &&
!item.contains(range.startContainer) && // 当前操作块不再进行操作
// 段落转列表会在段落后插入新列表
!hasClosestByAttribute(item, "data-node-id", operation.id) &&
@@ -1222,8 +1229,7 @@ export const turnsIntoTransaction = (options: {
isList = true;
return true;
}
- if (item.nextElementSibling && selectsElement[index + 1] &&
- item.nextElementSibling === selectsElement[index + 1]) {
+ if (selectsElement[index + 1] && getNextBlockSibling(item) === selectsElement[index + 1]) {
isContinue = true;
} else if (index !== selectsElement.length - 1) {
isContinue = false;
@@ -1263,7 +1269,7 @@ export const turnsIntoTransaction = (options: {
undoOperations.push({
action: "insert",
id,
- previousID: previousId || item.previousElementSibling?.getAttribute("data-node-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,
});
@@ -1272,7 +1278,7 @@ export const turnsIntoTransaction = (options: {
doOperations.push({
action: "insert",
id: tempItemId,
- previousID: tempItem.previousElementSibling?.getAttribute("data-node-id") || item.previousElementSibling?.getAttribute("data-node-id"),
+ 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,
});
@@ -1285,7 +1291,7 @@ export const turnsIntoTransaction = (options: {
action: "delete",
id,
});
- if (item === selectsElement[index + 1]?.previousElementSibling) {
+ if (selectsElement[index + 1] && item === getPreviousBlockSibling(selectsElement[index + 1])) {
previousId = id;
} else {
previousId = undefined;
@@ -1323,7 +1329,7 @@ export const turnsIntoTransaction = (options: {
undoOperations.push({
action: "insert",
id,
- previousID: doOperations[doOperations.length - 1]?.id || item.previousElementSibling?.getAttribute("data-node-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,
});
@@ -1340,7 +1346,7 @@ export const turnsIntoTransaction = (options: {
doOperations.push({
action: "insert",
id: tempItemId,
- previousID: tempItem.previousElementSibling?.getAttribute("data-node-id") || item.previousElementSibling?.getAttribute("data-node-id"),
+ 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,
});
@@ -1407,8 +1413,9 @@ export const turnsOneInto = async (options: {
}
}
const oldHTML = options.nodeElement.outerHTML;
- let previousId = options.nodeElement.previousElementSibling?.getAttribute("data-node-id");
- if (!options.nodeElement.previousElementSibling && options.protyle.block.showAll) {
+ const previousBlockElement = getPreviousBlockSibling(options.nodeElement);
+ let previousId = previousBlockElement?.getAttribute("data-node-id");
+ if (!previousBlockElement && options.protyle.block.showAll) {
const response = await fetchSyncPost("/api/block/getBlockRelevantIDs", {
id: options.id,
notebook: options.protyle.notebookId,