Skip to content

Commit

Permalink
fix: make variable names case-sensitive (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
gonfunko authored Aug 12, 2024
1 parent fa9367d commit 46854cd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { ScratchContinuousToolbox } from "./scratch_continuous_toolbox.js";
import "./scratch_continuous_category.js";
import "./scratch_comment_icon.js";
import "./scratch_dragger.js";
import "./scratch_variable_map.js";
import "./scratch_variable_model.js";
import "./scratch_connection_checker.js";
import "./events_block_comment_change.js";
Expand Down
25 changes: 25 additions & 0 deletions src/scratch_variable_map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* @license
* Copyright 2024 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

import * as Blockly from "blockly/core";

class ScratchVariableMap extends Blockly.VariableMap {
getVariable(name, type) {
// Variable names in Blockly are case-insensitive, but case sensitive in
// Scratch. Override the implementation to only return a variable whose name
// is identical to the one requested.
const variables = this.getVariablesOfType(type ?? "");
if (!variables.length) return null;
return variables.find((v) => v.getName() === name) ?? null;
}
}

Blockly.registry.register(
Blockly.registry.Type.VARIABLE_MAP,
Blockly.registry.DEFAULT,
ScratchVariableMap,
true
);

0 comments on commit 46854cd

Please sign in to comment.