Skip to content

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

:bug: Confirm removal of bound containers during list outdent https://github.com/siyuan-note/siyuan/issues/20173

Daniel3e070157452d
diff --git a/app/src/protyle/wysiwyg/list.ts b/app/src/protyle/wysiwyg/list.ts
index ca57cb2b84..c07a710c27 100644
--- a/app/src/protyle/wysiwyg/list.ts
+++ b/app/src/protyle/wysiwyg/list.ts
@@ -25,6 +25,7 @@ import {showMessage} from "../../dialog/message";
import {activateTrackedRangeInsertion, type ITrackedRangeInsertion} from "../util/trackedRange";
import {normalizeHTMLAssetIFrameBlockDOM} from "../../asset/html";
import {isTaskListMarker, nextTaskListMarker, nextTaskListStatus} from "./taskListMarker";
+import {confirmBlockRef} from "../../util/checkBlockRef";
const getLastChildBlock = (element: Element) => {
if (!element || !element.lastElementChild) {
@@ -1123,6 +1124,34 @@ export const listOutdent = async (protyle: IProtyle, liItemElements: Element[],
liItemElements.some((item) => !item.isConnected)) {
return;
}
+ // 只检查反向缩进时消失的容器,保留的正文块和移动的列表项不属于删除范围。
+ const removedElements: Element[] = [];
+ const topLevel = ["protyle-wysiwyg", "sb", "bq", "callout", "tab-item"].some(name =>
+ parentLiItemElement.classList.contains(name));
+ const flattenChild = !topLevel && liElement.childElementCount === 2 &&
+ (parentLiItemElement.childElementCount === 3 ||
+ (window.siyuan.config.editor.listLogicalOutdent &&
+ liElement.previousElementSibling?.classList.contains("protyle-action")));
+ if (topLevel || flattenChild) {
+ removedElements.push(...liItemElements);
+ }
+ if (liElement.childElementCount === liItemElements.length + 1) {
+ removedElements.push(liElement);
+ if (!topLevel && !flattenChild && parentLiItemElement.childElementCount === 3) {
+ removedElements.push(parentLiItemElement);
+ }
+ }
+ const removedIDs = removedElements.map(item => item.getAttribute("data-node-id")).filter(Boolean);
+ if (removedIDs.length > 0 && !await confirmBlockRef({
+ scope: "blocks", ids: removedIDs, exactIDs: removedIDs, deletedIDs: removedIDs,
+ notebook: protyle.notebookId,
+ }, protyle)) {
+ return;
+ }
+ if (!liElement.isConnected || !parentLiItemElement.isConnected ||
+ liItemElements.some(item => !item.isConnected || item.parentElement !== liElement)) {
+ return;
+ }
activateTrackedRangeInsertion(trackedRangeInsertion);
liItemElements.forEach(item => {
item.removeAttribute("select-start");
diff --git a/app/src/protyle/wysiwyg/listOutdent.test.ts b/app/src/protyle/wysiwyg/listOutdent.test.ts
index 3cddad5c28..446da97f50 100644
--- a/app/src/protyle/wysiwyg/listOutdent.test.ts
+++ b/app/src/protyle/wysiwyg/listOutdent.test.ts
@@ -81,7 +81,7 @@ class TestElement {
}
}
-const fixture = (single: boolean, containerClass = "tab-item") => {
+const fixture = (single: boolean, containerClass = "tab-item", confirmed = true) => {
const attr = () => new TestElement("protyle-attr");
const paragraph = new TestElement("p", "empty-paragraph").append(new TestElement("editable"), attr());
const item = new TestElement("li", "empty-item").append(new TestElement("protyle-action"), paragraph, attr());
@@ -95,6 +95,7 @@ const fixture = (single: boolean, containerClass = "tab-item") => {
const tabs = new TestElement("tabs", "tabs").append(container, otherTab, attr());
new TestElement("protyle-wysiwyg").append(tabs);
const operations: {doOperations: IOperation[], undoOperations: IOperation[]}[] = [];
+ const checks: Array<{ids: string[], exactIDs: string[], deletedIDs: string[]}> = [];
let focused: TestElement;
const exports: any = {};
const dependencies = {
@@ -102,6 +103,10 @@ const fixture = (single: boolean, containerClass = "tab-item") => {
getPreviousBlockSibling: (element: TestElement) => element.previousElementSibling,
getEmbedChildOperationContext: (): void => undefined,
activateTrackedRangeInsertion: (): void => undefined,
+ confirmBlockRef: async (options: {ids: string[], exactIDs: string[], deletedIDs: string[]}) => {
+ checks.push(options);
+ return confirmed;
+ },
moveToPrevious: (): void => undefined,
isBlockElement: (element: TestElement) => !!element.getAttribute("data-node-id"),
transaction: (_protyle: IProtyle, doOperations: IOperation[], undoOperations: IOperation[]) =>
@@ -121,7 +126,7 @@ const fixture = (single: boolean, containerClass = "tab-item") => {
};
const protyle = {block: {id: "doc", parentID: "doc"}};
return {
- paragraph, item, list, before, content, title, container, tabs, otherTab, operations,
+ paragraph, item, list, before, content, title, container, tabs, otherTab, operations, checks,
run: () => exports.listOutdent(protyle, [item], range),
focused: () => focused,
};
@@ -139,6 +144,9 @@ for (const single of [false, true]) {
assert.equal(f.tabs.childElementCount, 3);
assert.equal(f.focused(), f.container);
assert.equal(f.operations.length, 1);
+ assert.deepEqual(Array.from(f.checks[0].ids), single ? ["empty-item", "list"] : ["empty-item"]);
+ assert.deepEqual(Array.from(f.checks[0].exactIDs), Array.from(f.checks[0].ids));
+ assert.deepEqual(Array.from(f.checks[0].deletedIDs), Array.from(f.checks[0].ids));
const {doOperations, undoOperations} = f.operations[0];
assert.equal(doOperations[0].action, "move");
assert.equal(doOperations[0].id, "empty-paragraph");
@@ -158,3 +166,14 @@ for (const single of [false, true]) {
}
});
}
+
+for (const single of [false, true]) {
+ test(`cancelling ${single ? "single" : "partial"} list outdent preserves the editor and sends no transaction`, async () => {
+ const f = fixture(single, "tab-item", false);
+ const before = f.tabs.outerHTML;
+ await f.run();
+ assert.equal(f.tabs.outerHTML, before);
+ assert.equal(f.operations.length, 0);
+ assert.equal(f.focused(), undefined);
+ });
+}