Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions newIDE/app/src/EventsSheet/ParameterFields/VariableField.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ export const getRootVariableName = (name: string): string => {
: name;
};

const isRootVariableDeclared = (
variableName: string,
variablesContainers?: Array<gdVariablesContainer>
) => {
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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -316,20 +323,17 @@ export default (React.forwardRef<Props, VariableFieldInterface>(
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
Expand Down
Loading