Skip to content

Commit 5abf38d

Browse files
authored
Fix staccato/slur listener name collision on nested blocks (#5771)
Include block ID in listener name so nesting staccato inside slur (or vice versa) no longer destroys the outer cleanup listener. Signed-off-by: Ady0333 <adityashinde1525@gmail.com>
1 parent 81829a6 commit 5abf38d

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

js/turtleactions/OrnamentActions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function setupOrnamentActions(activity) {
4747

4848
tur.singer.staccato.push(1 / value);
4949

50-
const listenerName = "_staccato_" + turtle;
50+
const listenerName = "_staccato_" + turtle + "_" + blk;
5151
if (blk !== undefined && blk in activity.blocks.blockList) {
5252
activity.logo.setDispatchBlock(blk, turtle, listenerName);
5353
} else if (MusicBlocks.isRun) {
@@ -77,7 +77,7 @@ function setupOrnamentActions(activity) {
7777
activity.logo.notation.notationBeginSlur(turtle);
7878
}
7979

80-
const listenerName = "_staccato_" + turtle;
80+
const listenerName = "_staccato_" + turtle + "_" + blk;
8181
if (blk !== undefined && blk in activity.blocks.blockList) {
8282
activity.logo.setDispatchBlock(blk, turtle, listenerName);
8383
} else if (MusicBlocks.isRun) {

js/turtleactions/__tests__/OrnamentActions.test.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,13 @@ describe("OrnamentActions", () => {
109109
global.MusicBlocks.isRun = isRun;
110110
if (nullMouse) global.Mouse.getMouseFromTurtle = () => null;
111111
Singer.OrnamentActions.setStaccato(2, 0, blk);
112+
const expectedName = "_staccato_0_" + blk;
112113
expect(turtle.singer.staccato).toEqual([0.5]);
113114
expect(dispatchCalls.length).toBe(expectDispatch ? 1 : 0);
114115
expect(listenerCalls.length).toBe(1);
115-
if (expectMouseListener) expect(mouseMB.listeners).toContain("_staccato_0");
116-
else expect(mouseMB.listeners).not.toContain("_staccato_0");
117-
listenerFunctions["_staccato_0"]();
116+
if (expectMouseListener) expect(mouseMB.listeners).toContain(expectedName);
117+
else expect(mouseMB.listeners).not.toContain(expectedName);
118+
listenerFunctions[expectedName]();
118119
expect(turtle.singer.staccato).toEqual([]);
119120
});
120121
}
@@ -195,9 +196,10 @@ describe("OrnamentActions", () => {
195196
expect(beginSlurCalls.length).toBe(expectBeginSlur ? 1 : 0);
196197
expect(dispatchCalls.length).toBe(expectDispatch ? 1 : 0);
197198
expect(listenerCalls.length).toBe(1);
198-
if (expectMouseListener) expect(mouseMB.listeners).toContain("_staccato_0");
199-
else expect(mouseMB.listeners).not.toContain("_staccato_0");
200-
listenerFunctions["_staccato_0"]();
199+
const expectedName = "_staccato_0_" + blk;
200+
if (expectMouseListener) expect(mouseMB.listeners).toContain(expectedName);
201+
else expect(mouseMB.listeners).not.toContain(expectedName);
202+
listenerFunctions[expectedName]();
201203
expect(turtle.singer.staccato).toEqual([]);
202204
expect(endSlurCalls.length).toBe(expectBeginSlur ? 1 : 0);
203205
});

0 commit comments

Comments
 (0)