diff --git a/newIDE/app/src/EventsSheet/ParameterFields/VariableField.js b/newIDE/app/src/EventsSheet/ParameterFields/VariableField.js index 5cd46fc327d7..628c24a4d878 100644 --- a/newIDE/app/src/EventsSheet/ParameterFields/VariableField.js +++ b/newIDE/app/src/EventsSheet/ParameterFields/VariableField.js @@ -96,6 +96,18 @@ export const getRootVariableName = (name: string): string => { : name; }; +const isRootVariableDeclared = ( + variableName: string, + variablesContainers?: Array +) => { + return ( + !variablesContainers || + variablesContainers.some(variablesContainer => + variablesContainer.has(getRootVariableName(variableName)) + ) + ); +}; + // TODO: the entire VariableField could be reworked to be a "real" GenericExpressionField // (of type: "variable" or the legacy: "scenevar", "globalvar" or "objectvar"). This will // ensure we 100% validate and can autocomplete what is entered (and we can have also a simpler @@ -139,12 +151,7 @@ export const quicklyAnalyzeVariableName = ( const rootVariableName = getRootVariableName(name); // Check at least the name of the root variable, it's the best we can do. - if ( - variablesContainers && - !variablesContainers.some(variablesContainer => - variablesContainer.has(rootVariableName) - ) - ) { + if (!isRootVariableDeclared(rootVariableName, variablesContainers)) { // $FlowFixMe[incompatible-type] return VariableNameQuickAnalyzeResults.UNDECLARED_VARIABLE; } @@ -316,20 +323,17 @@ export default (React.forwardRef( const fieldCurrentValue = field.current ? field.current.getInputValue() : value; - const isRootVariableDeclared = - projectScopedContainersAccessor && - projectScopedContainersAccessor - .get() - .getVariablesContainersList() - .has(getRootVariableName(fieldCurrentValue)); onChange(fieldCurrentValue); onOpenDialog({ variableName: fieldCurrentValue, - shouldCreate: !isRootVariableDeclared, + shouldCreate: !isRootVariableDeclared( + fieldCurrentValue, + variablesContainers + ), }); }, - [onChange, onOpenDialog, projectScopedContainersAccessor, value] + [onChange, onOpenDialog, value, variablesContainers] ); const description = parameterMetadata