Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion dist/datamodel/node/data/MatlabVariableNode.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions dist/datamodel/node/data/MatlabVariableNode.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/datamodel/node/data/MatlabVariableNode.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "data-explorer-core",
"version": "1.11.0",
"version": "1.11.1",
"description": "Parser, data model, and node schema for Simulink data-dictionary, model, MAT-file, and project files. Presentation-independent; embeddable in-process.",
"license": "BSD-3-Clause",
"type": "module",
Expand Down
8 changes: 8 additions & 0 deletions src/datamodel/node/data/MatlabVariableNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,14 @@ export default class MatlabVariableNode extends DataNode {
}
this._applyParsed(parsed);
this._markModified();
// _applyParsed rebuilds this node's children from the text, so restating a
// value crosses the same has-children/has-none line an add or a remove does
// (childEdit.ts notifies for those). A parent whose row for this node depends
// on its shape — a Simulink.Parameter's Value row — has to follow, or a matrix
// retyped as a scalar leaves it holding an expander onto nothing until the file
// is re-read. The notification goes both ways: the same hook brings the row
// back when a hidden scalar value node grows elements.
this.parent?.childStructureChanged(this);
return true;
}
return DataNode.prototype.setProperty.call(this, propName, stringValue);
Expand Down
55 changes: 55 additions & 0 deletions test/parameterNode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,61 @@ describe('ParameterNode — Value row follows a structural edit', () => {
expect(p.displayValue).toBe('"hello"');
});

// The other way to cross that line: not adding or removing an element, but
// restating the whole value. The table's Value cell on the Value row commits
// through MatlabVariableNode.setProperty, which rebuilds the node's children from
// the text — and used to tell nobody, so a matrix retyped as a scalar left the
// Parameter holding a childless Value row. The consumer that repaints from the
// node it mutated (rather than from a re-read of the file) then paints a row a
// re-read would not: an expander onto nothing, under a scalar.
it('drops the row when the value row itself is retyped as a scalar', () => {
const p = parseParamValue([1, 2]);
const valueNode = p.children[0] as any;
expect(valueNode.setProperty('Value', '42')).toBe(true);
expect(valueNode.children.length).toBe(0);
expect(p.children.length).toBe(0);
expect(p.displayValue).toBe('42');
expect(serializedValue(p)).toBe(42);
});

it('keeps the row when the value row is retyped as another array', () => {
const p = parseParamValue([1, 2]);
const valueNode = p.children[0] as any;
expect(valueNode.setProperty('Value', '[7 8 9]')).toBe(true);
// The SAME node: it is still this Parameter's _valueNode.
expect(p.children).toEqual([valueNode]);
expect(p.displayValue).toBe('[7 8 9]');
});

it('brings the row back when a hidden scalar value node becomes an array', () => {
// The inverse, and the reason the notification is not a one-way "drop it". A
// TYPED scalar keeps its value node with no row of its own (the node is what
// writes int32 back out), so the row has to appear when that node grows
// children. Reached by a caller holding the value node itself rather than by the
// table, which has no row to double-click — but it is the same hook, and a
// one-way version of it would be a latent half-fix.
const p = parseParamValue({ _type: 'int32', _value: '5' });
expect(p.children.length).toBe(0);
const valueNode = (p as any)._valueNode;
expect(valueNode.setProperty('Value', '[1 2]')).toBe(true);
expect(p.children).toEqual([valueNode]);
expect(p.displayValue).toBe('[1 2]');
});

it('adds the row when the ENTRY\'s own value is retyped as an array', () => {
// The path the table actually takes for a scalar Parameter — there is no Value
// row to edit, so the edit lands on the entry and goes through
// ParameterNode.setProperty, which re-adopts the value node and so decides the
// row itself. Pinned beside the others because a consumer repainting from the
// mutated node needs BOTH spellings of "the value changed shape" to leave the
// same tree a re-read would build.
const p = parseParamValue(5);
expect(p.setProperty('Value', '[1 2]')).toBe(true);
expect(p.children.map((c) => c.name)).toEqual(['Value']);
expect(p.children[0].children.length).toBe(2);
expect(p.displayValue).toBe('[1 2]');
});

it('does not drop another class\'s Value row when its array collapses', () => {
// Scoping guard, the counterpart of the parse-time one: a property bag's rows
// ARE its properties, so MyGain.Value must survive becoming a scalar. Only
Expand Down