Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/flyout_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,7 @@ export abstract class Flyout extends DeleteArea implements IFlyout {

// Clone the block.
// TODO(#7432): Add a saveIds parameter to `save`.
const json = blocks.save(oldBlock) as blocks.State;
const json = blocks.save(oldBlock, {saveIds: false}) as blocks.State;
// Normallly this resizes leading to weird jumps. Save it for terminateDrag.
targetWorkspace.setResizesEnabled(false);
const block = blocks.append(json, targetWorkspace) as BlockSvg;
Expand Down
26 changes: 21 additions & 5 deletions core/serialization/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,21 @@ export function save(
addInputBlocks = true,
addNextBlocks = true,
doFullSerialization = true,
saveIds = true,
}: {
addCoordinates?: boolean;
addInputBlocks?: boolean;
addNextBlocks?: boolean;
doFullSerialization?: boolean;
saveIds?: boolean;
} = {},
): State | null {
if (block.isInsertionMarker()) {
return null;
}

const state = {
'type': block.type,
'id': block.id,
'id': saveIds ? block.id : undefined,
};

if (addCoordinates) {
Expand All @@ -122,12 +123,22 @@ export function save(
if (addInputBlocks) {
// AnyDuringMigration because: Argument of type '{ type: string; id:
// string; }' is not assignable to parameter of type 'State'.
saveInputBlocks(block, state as AnyDuringMigration, doFullSerialization);
saveInputBlocks(
block,
state as AnyDuringMigration,
doFullSerialization,
saveIds,
);
}
if (addNextBlocks) {
// AnyDuringMigration because: Argument of type '{ type: string; id:
// string; }' is not assignable to parameter of type 'State'.
saveNextBlocks(block, state as AnyDuringMigration, doFullSerialization);
saveNextBlocks(
block,
state as AnyDuringMigration,
doFullSerialization,
saveIds,
);
}

// AnyDuringMigration because: Type '{ type: string; id: string; }' is not
Expand Down Expand Up @@ -270,6 +281,7 @@ function saveInputBlocks(
block: Block,
state: State,
doFullSerialization: boolean,
saveIds: boolean,
) {
const inputs = Object.create(null);
for (let i = 0; i < block.inputList.length; i++) {
Expand All @@ -278,6 +290,7 @@ function saveInputBlocks(
const connectionState = saveConnection(
input.connection as Connection,
doFullSerialization,
saveIds,
);
if (connectionState) {
inputs[input.name] = connectionState;
Expand All @@ -301,13 +314,15 @@ function saveNextBlocks(
block: Block,
state: State,
doFullSerialization: boolean,
saveIds: boolean,
) {
if (!block.nextConnection) {
return;
}
const connectionState = saveConnection(
block.nextConnection,
doFullSerialization,
saveIds,
);
if (connectionState) {
state['next'] = connectionState;
Expand All @@ -326,6 +341,7 @@ function saveNextBlocks(
function saveConnection(
connection: Connection,
doFullSerialization: boolean,
saveIds: boolean,
): ConnectionState | null {
const shadow = connection.getShadowState(true);
const child = connection.targetBlock();
Expand All @@ -337,7 +353,7 @@ function saveConnection(
state['shadow'] = shadow;
}
if (child && !child.isShadow()) {
state['block'] = save(child, {doFullSerialization});
state['block'] = save(child, {doFullSerialization, saveIds});
}
return state;
}
Expand Down
6 changes: 6 additions & 0 deletions tests/mocha/jso_serialization_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ suite('JSO Serialization', function () {
assertProperty(jso, 'id', 'id0');
});

test('saveId false', function () {
const block = this.workspace.newBlock('row_block');
const jso = Blockly.serialization.blocks.save(block, {saveIds: false});
assertProperty(jso, 'id', undefined);
});

suite('Attributes', function () {
suite('Collapsed', function () {
test('True', function () {
Expand Down