Skip to content

Commit 83682a1

Browse files
Copilotmikebarkmin
andcommitted
Fix bug when creating Array nodes with createNewOnEdgeDrop option
Co-authored-by: mikebarkmin <2592379+mikebarkmin@users.noreply.github.com>
1 parent 3d90c21 commit 83682a1

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

src/MemoryView.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,38 @@ export const MemoryView = () => {
181181
});
182182
const id = getId();
183183

184+
// Handle Array type specially
185+
let objAttributes: Record<string, Attribute>;
186+
if (klassName === "Array") {
187+
const length = window.prompt(`Length of the array?`);
188+
if (length == null) return;
189+
const tempAttributes: Record<string, Attribute> = {
190+
length: {
191+
dataType: "int",
192+
value: Number.parseInt(length),
193+
},
194+
};
195+
for (let i = 0; i < Number.parseInt(length); i++) {
196+
tempAttributes[`[${i}]`] = {
197+
dataType: klassName,
198+
value: undefined,
199+
};
200+
}
201+
objAttributes = tempAttributes;
202+
} else if (klass) {
203+
objAttributes = createAttributesForObject(klass.attributes);
204+
} else {
205+
// Unknown klass type, cannot create object
206+
return;
207+
}
208+
184209
const newNode: CustomNodeType = {
185210
id,
186211
type: "object",
187212
position,
188213
data: {
189214
klass: klassName,
190-
attributes: createAttributesForObject(klass.attributes),
215+
attributes: objAttributes,
191216
position,
192217
},
193218
};

0 commit comments

Comments
 (0)