MCPcopy
hub / github.com/RaspberryPiFoundation/blockly / rename

Function rename

packages/blockly/core/procedures.ts:205–231  ·  view source on GitHub ↗
(this: Field, name: string)

Source from the content-addressed store, hash-verified

203 * @returns The accepted name.
204 */
205export function rename(this: Field, name: string): string {
206 const block = this.getSourceBlock();
207 if (!block) {
208 throw new UnattachedFieldError();
209 }
210
211 // Strip leading and trailing whitespace. Beyond this, all names are legal.
212 name = name.trim();
213
214 const legalName = findLegalName(name, block);
215 if (isProcedureBlock(block) && !block.isInsertionMarker()) {
216 block.getProcedureModel().setName(legalName);
217 }
218 const oldName = this.getValue();
219 if (oldName !== name && oldName !== legalName) {
220 // Rename any callers.
221 const blocks = block.workspace.getAllBlocks(false);
222 for (let i = 0; i < blocks.length; i++) {
223 // Assume it is a procedure so we can check.
224 const procedureBlock = blocks[i] as unknown as ProcedureBlock;
225 if (procedureBlock.renameProcedure) {
226 procedureBlock.renameProcedure(oldName as string, legalName);
227 }
228 }
229 }
230 return legalName;
231}
232
233/**
234 * Construct the blocks required by the flyout for the procedure category.

Callers 2

buildCompiledFunction · 0.85
convertToMdxFunction · 0.85

Calls 8

findLegalNameFunction · 0.85
isProcedureBlockFunction · 0.85
isInsertionMarkerMethod · 0.80
getProcedureModelMethod · 0.80
setNameMethod · 0.65
getSourceBlockMethod · 0.45
getValueMethod · 0.45
getAllBlocksMethod · 0.45

Tested by

no test coverage detected