Skip to content

Commit 13801c2

Browse files
committed
Line: follow the new dropTarget default in the tests and comments
1 parent 488205d commit 13801c2

4 files changed

Lines changed: 12 additions & 7 deletions

File tree

client/js/editor/sidebar/properties.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5590,8 +5590,8 @@ class PropertiesModule extends SidebarModule {
55905590
};
55915591

55925592
// the line takes widgets in like a holder does: the toggle switches its
5593-
// dropTarget between the default (the plain widgets stops usually are) and
5594-
// an empty list, which matches nothing. A more specific dropTarget can be
5593+
// dropTarget between the plain widgets stops usually are and the default
5594+
// empty list, which matches nothing. A more specific dropTarget can be
55955595
// written in the property list below, the same way a holder's is.
55965596
const takeDrops = addLineToggle('Drag widgets in to add stops', 'lineTakeDrops', 'Let a widget dragged onto the line become a stop of it - during play as well as in edit mode');
55975597
this.addPropertyListener(widget, 'dropTarget', ()=>takeDrops.checked = asArray(widget.get('dropTarget')).filter(t=>t).length > 0);

client/js/widgets/line.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ export class Line extends Widget {
3434
// A line takes widgets in like a holder: what dropTarget matches becomes
3535
// a stop when it is dropped onto the path - during play as well as in
3636
// edit mode - and comes off the list again when it is dragged away. The
37-
// default takes the plain widgets stops usually are, an empty list none.
37+
// default empty list matches nothing, so a line takes drops only once it
38+
// is given one - { type: null } for the plain widgets stops usually are.
3839
dropTarget: [],
3940

4041
// properties applied to a widget when it enters / leaves the line

tests/client/line-widget.test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,10 +517,12 @@ describe('dragging a widget onto a line to make it a stop', () => {
517517
let line, token;
518518

519519
beforeEach(() => {
520+
// a line takes nothing by default, so this one opts in with the dropTarget
521+
// the editor's "Drag widgets in to add stops" toggle writes
520522
line = createLine({ id: 'drop-line', x: 100, y: 100, width: 200, height: 40, autoSpaceStops: false,
521-
lineStart: { x: 0, y: 0 }, lineEnd: { x: 200, y: 0 } });
523+
lineStart: { x: 0, y: 0 }, lineEnd: { x: 200, y: 0 }, dropTarget: { type: null } });
522524
token = new Widget('drop-token');
523-
// a plain widget has no type, which is what the default dropTarget takes
525+
// a plain widget has no type, which is what that dropTarget takes
524526
addWidget({ id: 'drop-token', x: 130, y: 80, width: 40, height: 40 }, token);
525527
token.coordGlobalFromCoordLocal = coord => ({ x: token.get('x') + coord.x, y: token.get('y') + coord.y });
526528
// the candidate lines are collected once when the drag starts
@@ -546,7 +548,9 @@ describe('dragging a widget onto a line to make it a stop', () => {
546548
});
547549

548550
test('a line whose dropTarget matches nothing never takes a dropped widget', async () => {
549-
await line.set('dropTarget', []);
551+
// null is not storable, so this falls back to the default: an empty list
552+
await line.set('dropTarget', null);
553+
expect(line.get('dropTarget')).toEqual([]);
550554
expect(line.stopDropTarget(token, { x: 150, y: 100 })).toBeNull();
551555
expect(token.lineStopDropTarget()).toBeNull();
552556
});

tests/testcafe/editor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,5 +267,5 @@ test('Line widget in edit mode', async t => {
267267
.click('#editorToolbar > div > [icon=delete_forever]');
268268
// the added stop's id is derived from the existing stops instead of being
269269
// random, so the compared state no longer depends on the seeded rand() stream
270-
await compareState(t, '7da80b26d6a3d7352f9ae5d58dce6fab');
270+
await compareState(t, 'a82be0977ae859e03f353c51aa947db9');
271271
});

0 commit comments

Comments
 (0)