Skip to content

Commit 666c6de

Browse files
committed
[FIX] figures: fix non-deterministic figure order export
In a3ddce5, we introduced a way to ensure deterministic order of figures when exporting a sheet. However, this way was not applied when duplicating sheets, which could lead to non-deterministic order of figures in the duplicated sheet. closes #7526 Task: 5092281 Signed-off-by: Adrien Minne (adrm) <[email protected]>
1 parent 7578897 commit 666c6de

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/plugins/core/figures.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ export class FigurePlugin extends CorePlugin<FigureState> implements FigureState
124124
}
125125
break;
126126
case "DUPLICATE_SHEET": {
127-
for (const figureId in this.figures[cmd.sheetId]) {
127+
for (const figure of this.getFigures(cmd.sheetId)) {
128+
const figureId = figure.id;
128129
const fig = this.figures[cmd.sheetId]?.[figureId];
129130
if (!fig) {
130131
continue;

tests/collaborative/collaborative.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,3 +1110,31 @@ test("UI plugins cannot refuse core command and de-synchronize the users", () =>
11101110
expect([alice, bob]).toHaveSynchronizedValue((user) => getCellContent(user, "A1"), "hello");
11111111
featurePluginRegistry.remove("myUIPlugin");
11121112
});
1113+
1114+
test("Export of figures should be in the same order in all users", () => {
1115+
const { network, alice, bob, charlie } = setupCollaborativeEnv();
1116+
charlie.dispatch("CREATE_FIGURE", {
1117+
figureId: "figureId",
1118+
tag: "tag",
1119+
offset: { x: 0, y: 0 },
1120+
col: 4,
1121+
row: 7,
1122+
size: { width: 100, height: 100 },
1123+
sheetId: "Sheet1",
1124+
});
1125+
redo(charlie);
1126+
1127+
charlie.dispatch("UPDATE_CELL", { col: 4, row: 7, content: "2", sheetId: "Sheet1" });
1128+
undo(charlie);
1129+
alice.dispatch("DUPLICATE_SHEET", {
1130+
sheetId: "Sheet1",
1131+
sheetIdTo: "duplicateSheetId",
1132+
sheetNameTo: "Copy of Sheet1",
1133+
});
1134+
network.concurrent(() => {
1135+
redo(charlie);
1136+
bob.dispatch("DELETE_FIGURE", { figureId: "figureId", sheetId: "Sheet1" });
1137+
});
1138+
expect([alice, bob, charlie]).toHaveSynchronizedEvaluation();
1139+
expect([alice, bob, charlie]).toHaveSynchronizedExportedData();
1140+
});

0 commit comments

Comments
 (0)