Skip to content

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

:bug: Preserve detached state when updating legacy database icons https://github.com/siyuan-note/siyuan/issues/20632

Daniel73e66318a05f
diff --git a/app/src/protyle/render/av/blockIcon.test.ts b/app/src/protyle/render/av/blockIcon.test.ts
index cdda67f692..58d5f1cfb4 100644
--- a/app/src/protyle/render/av/blockIcon.test.ts
+++ b/app/src/protyle/render/av/blockIcon.test.ts
@@ -199,6 +199,33 @@ describe("database item icons", () => {
assert.equal(bound.operations.length, 0);
});
+ it("preserves detached state and undo values when editing legacy row icons", async () => {
+ for (const layout of ["table", "list", "gallery", "kanban", "calendar"] as TAVView[]) {
+ const h = createHarness(layout);
+ h.cell.value.block.id = "20230101000000-legacy1";
+ h.open();
+ assert.equal(h.panel.type, "av");
+ let previousIcon = "";
+ for (const icon of ["1f600", "1f680", ""]) {
+ const previousValue = JSON.parse(JSON.stringify(h.cell.value)) as IAVCellValue;
+ previousValue.block.icon = previousIcon;
+ h.panel.callback(icon);
+ await Promise.resolve();
+ const op = h.operations[h.operations.length - 1];
+ const nextValue = op.doOperations[0].data as IAVCellValue;
+ assert.equal(nextValue.isDetached, true);
+ assert.equal(nextValue.block.id, "20230101000000-legacy1");
+ assert.equal(nextValue.block.content, "Title");
+ assert.equal(nextValue.block.icon, icon);
+ assert.equal(op.doOperations[0].rowID, "row");
+ assert.equal(op.doOperations[0].keyID, "primary");
+ assert.deepEqual(JSON.parse(JSON.stringify(op.undoOperations[0].data)), previousValue);
+ assert.equal(h.cell.value.isDetached, true);
+ previousIcon = icon;
+ }
+ }
+ });
+
it("keeps the original row through virtual scrolling and preserves later title edits", async () => {
const h = createHarness();
h.open();
diff --git a/app/src/protyle/render/av/cell.ts b/app/src/protyle/render/av/cell.ts
index 0d6de6ffa4..533b61ef1b 100644
--- a/app/src/protyle/render/av/cell.ts
+++ b/app/src/protyle/render/av/cell.ts
@@ -118,8 +118,11 @@ export const openAVCellIcon = (protyle: IProtyle, target: HTMLElement) => {
}
const oldValue = cloneAVCellValueSnapshot(currentValue);
oldValue.block.icon = oldValue.block.icon || "";
- void updateCellsValue(protyle, blockElement, {...oldValue.block, icon: unicode},
- undefined, undefined, undefined, false, false, false, [{
+ // 图标更新保留条目的绑定状态,兼容仍带有块 ID 的旧版非绑定条目。
+ void updateCellsValue(protyle, blockElement, {
+ ...oldValue,
+ block: {...oldValue.block, icon: unicode},
+ }, undefined, undefined, undefined, false, false, false, [{
groupID: "", rowID, colID, rowIndex: 0, colIndex: -1,
cell: {...currentCell, id: currentCell?.id || cellElement.dataset.id, value: oldValue},
column: {id: colID, type: "block"} as IAVColumn,