Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: JSON deserialization of certain collapsed blocks #6126

Merged
merged 4 commits into from
Apr 28, 2022
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
7 changes: 4 additions & 3 deletions blockly_compressed.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion blockly_compressed.js.map

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions blocks/procedures.js
Original file line number Diff line number Diff line change
Expand Up @@ -721,10 +721,10 @@ const PROCEDURE_CALL_COMMON = {
if (!mutatorOpen) {
this.quarkConnections_ = {};
this.quarkIds_ = null;
}
if (!paramIds) {
// Reset the quarks (a mutator is about to open).
return;
} else {
// fix #6091 - this call could cause an error when outside if-else
// expanding block while mutating prevents another error (ancient fix)
this.setCollapsed(false);
}
// Test arguments (arrays of strings) for changes. '\n' is not a valid
// argument name character, so it is a valid delimiter here.
Expand All @@ -736,7 +736,6 @@ const PROCEDURE_CALL_COMMON = {
if (paramIds.length !== paramNames.length) {
throw RangeError('paramNames and paramIds must be the same length.');
}
this.setCollapsed(false);
if (!this.quarkIds_) {
// Initialize tracking for this block.
this.quarkConnections_ = {};
Expand Down
2 changes: 1 addition & 1 deletion blocks_compressed.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion blocks_compressed.js.map

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions core/serialization/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,12 @@ const initBlock = function(block, rendered) {

blockSvg.initSvg();
blockSvg.render(false);
// fixes #6076 JSO deserialization doesn't
// set .iconXY_ property so here it will be set
const icons = block.getIcons();
for (let i = 0; i < icons.length; i++) {
icons[i].computeIconLocation();
}
} else {
block.initModel();
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blockly",
"version": "8.0.0",
"version": "8.0.1",
"description": "Blockly is a library for building visual programming editors.",
"keywords": [
"blockly"
Expand Down
40 changes: 40 additions & 0 deletions tests/mocha/serializer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1674,12 +1674,52 @@ Serializer.Mutations.Procedure.Caller = new SerializerTestCase(
'</mutation>' +
'</block>' +
'</xml>');
Serializer.Mutations.Procedure.CollapsedProceduresCallreturn = new SerializerTestCase(
'CollapsedProceduresCallreturn',
'<xml xmlns="https://developers.google.com/blockly/xml">' +
'<variables>' +
'<variable id="aaaaaaaaaaaaaaaaaaaa">x</variable>' +
'</variables>' +
'<block type="procedures_defreturn" id="id******************" x="42" y="42">' +
'<mutation>' +
'<arg name="x" varid="aaaaaaaaaaaaaaaaaaaa"></arg>' +
'</mutation>' +
'<field name="NAME">do something</field>' +
'<comment pinned="false" h="80" w="160">Describe this function...</comment>' +
'</block>' +
'<block type="procedures_callreturn" id="id1*****************" collapsed="true" x="52" y="52">' +
'<mutation name="do something">' +
'<arg name="x"></arg>' +
'</mutation>' +
'</block>' +
'</xml>');
Serializer.Mutations.Procedure.CollapsedProceduresCallnoreturn = new SerializerTestCase(
'CollapsedProceduresCallnoreturn',
'<xml xmlns="https://developers.google.com/blockly/xml">' +
'<variables>' +
'<variable id="aaaaaaaaaaaaaaaaaaaa">x</variable>' +
'</variables>' +
'<block type="procedures_defnoreturn" id="id******************" x="42" y="42">' +
'<mutation>' +
'<arg name="x" varid="aaaaaaaaaaaaaaaaaaaa"></arg>' +
'</mutation>' +
'<field name="NAME">do something</field>' +
'<comment pinned="false" h="80" w="160">Describe this function...</comment>' +
'</block>' +
'<block type="procedures_callnoreturn" id="id1*****************" collapsed="true" x="52" y="52">' +
'<mutation name="do something">' +
'<arg name="x"></arg>' +
'</mutation>' +
'</block>' +
'</xml>');
Serializer.Mutations.Procedure.testCases = [
Serializer.Mutations.Procedure.NoMutation,
Serializer.Mutations.Procedure.Variables,
Serializer.Mutations.Procedure.NoStatements,
Serializer.Mutations.Procedure.IfReturn,
Serializer.Mutations.Procedure.Caller,
Serializer.Mutations.Procedure.CollapsedProceduresCallreturn,
Serializer.Mutations.Procedure.CollapsedProceduresCallnoreturn,
];

Serializer.Mutations.Procedure.Names = new SerializerTestSuite('Names');
Expand Down