Skip to content

Commit

Permalink
fix: copy-pasting procedure definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
BeksOmega committed Jan 9, 2023
1 parent 6bd64a3 commit 8b4b57c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 19 additions & 1 deletion blocks/procedures.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const {Block} = goog.requireType('Blockly.Block');
// TODO (6248): Properly import the BlockDefinition type.
/* eslint-disable-next-line no-unused-vars */
const BlockDefinition = Object;
const {isProcedureBlock} = goog.require('Blockly.procedures.IProcedureModel');
const {ObservableProcedureModel} = goog.require('Blockly.procedures.ObservableProcedureModel');
const {ObservableParameterModel} = goog.require('Blockly.procedures.ObservableParameterModel');
const {config} = goog.require('Blockly.config');
Expand Down Expand Up @@ -573,7 +574,9 @@ const procedureDefMutator = {
const map = this.workspace.getProcedureMap();
const procedureId = state['procedureId'];
if (procedureId && procedureId != this.model_.getId() &&
map.has(procedureId)) {
map.has(procedureId) &&
(this.isInsertionMarker() ||
this.noBlockHasClaimedModel_(procedureId))) {
if (map.has(this.model_.getId())) {
map.delete(this.model_.getId());
}
Expand All @@ -595,6 +598,21 @@ const procedureDefMutator = {
Procedures.mutateCallers(this);
},

/**
* Returns true if there is no definition block currently associated with the
* given procedure ID. False otherwise.
* @param {string} procedureId The ID of the procedure to check for a claiming
* block.
* @return {boolean} True if there is no definition block currently associated
* with the given procedure ID. False otherwise.
*/
noBlockHasClaimedModel_(procedureId) {
const model = this.workspace.getProcedureMap().get(procedureId);
return this.workspace.getAllBlocks(false).every(
(b) => !isProcedureBlock(b) || !b.isProcedureDef() ||
b.getProcedureModel() !== model);
},

/**
* Populate the mutator's dialog with this block's components.
* @param {!Workspace} workspace Mutator's workspace.
Expand Down
2 changes: 2 additions & 0 deletions core/interfaces/i_procedure_block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import type {Block} from '../block.js';
import {IProcedureModel} from './i_procedure_model.js';
import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.procedures.IProcedureModel');


/** The interface for a block which models a procedure. */
Expand Down

0 comments on commit 8b4b57c

Please sign in to comment.