From 0d4aefa6d4f5494b4d712f6ab7ca65f251914945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Davy=20H=C3=A9lard?= Date: Tue, 7 Apr 2026 17:27:28 +0200 Subject: [PATCH] Fix "Add or edit variables" button always creating variables for object variables --- .../ParameterFields/VariableField.js | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) 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