Skip to content

Commit

Permalink
fix: loading parameters for shareable procedure blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
BeksOmega committed Aug 22, 2023
1 parent b5f6f0b commit 80cab38
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
17 changes: 12 additions & 5 deletions plugins/block-shareable-procedures/src/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,13 +461,20 @@ const procedureDefMutator = {
this.model_ = map.get(procedureId);
}

if (state['params'] && !this.getProcedureModel().getParameters().length) {
for (let i = 0; i < state['params'].length; i++) {
const {name, id, paramId} = state['params'][i];
this.getProcedureModel().insertParameter(
new ObservableParameterModel(this.workspace, name, paramId, id), i);
const model = this.getProcedureModel();
const newParams = state['params'] ?? [];
const newIds = new Set(newParams.map((p) => p.id));
const currParams = model.getParameters();
for (let i = currParams.length - 1; i >= 0; i--) {
if (!newIds.has(currParams[i].getId)) {
model.deleteParameter(i);
}
}
for (let i = 0; i < newParams.length; i++) {
const {name, id, paramId} = state['params'][i];
this.getProcedureModel().insertParameter(
new ObservableParameterModel(this.workspace, name, paramId, id), i);
}

this.doProcedureUpdate();
this.setStatements_(state['hasStatements'] === false ? false : true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export abstract class ProcedureBase extends Blockly.Events.Abstract {
readonly procedure: Blockly.procedures.IProcedureModel) {
super();
this.workspaceId = workspace.id;
this.recordUndo = false;
}

/**
Expand Down

0 comments on commit 80cab38

Please sign in to comment.