Skip to content

Commit 36325fc

Browse files
committed
fix rename, remove hack
1 parent d9bac1c commit 36325fc

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

pxtblocks/plugins/functions/utils.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,22 @@ export function rename(this: Blockly.FieldTextInput, name: string) {
3232
const sourceBlock = this.sourceBlock_ as CommonFunctionBlock;
3333
const oldMutation = sourceBlock.mutationToDom();
3434

35-
const legalName = findLegalName(name, sourceBlock.workspace, sourceBlock);
35+
let legalName = name;
36+
const workspaces = getGlobalProgram()?.getAllWorkspaces()?.map(w => w.workspace) || [sourceBlock.workspace]
37+
38+
let didChange = true;
39+
while (didChange) {
40+
didChange = false;
41+
for (const workspace of workspaces) {
42+
const newName = findLegalName(legalName, workspace, sourceBlock);
43+
if (newName !== legalName) {
44+
legalName = newName;
45+
didChange = true;
46+
break;
47+
}
48+
}
49+
}
50+
3651
const oldName = this.getValue();
3752

3853
if (!name) return oldName;
@@ -458,8 +473,7 @@ export function flyoutCategory(workspace: Blockly.WorkspaceSvg) {
458473
if (program) {
459474
program.refreshSymbols?.();
460475

461-
// feels hacky did i miss easy way to do this? easy way for now
462-
const currentFile = (program as any).currentlyLoadedFile as string | undefined;
476+
const currentFile = program.getAllWorkspaces().find(w => w.workspace === workspace)?.fileName || pxt.MAIN_BLOCKS;
463477
const localNames = new Set(getAllFunctionDefinitionBlocks(workspace).map(f => f.getName().toLowerCase()));
464478

465479
for (const file of program.listFiles()) {

0 commit comments

Comments
 (0)