Skip to content

Commit c862b5e

Browse files
authored
feat: Beep when attempting constrained move on top-level block (#9635)
* feat: Beep when attempting constrained move on top-level block * chore: Remove errant `only` * refactor: Add and use `playErrorBeep()`
1 parent 83c8cac commit c862b5e

3 files changed

Lines changed: 11 additions & 0 deletions

File tree

packages/blockly/core/dragging/block_drag_strategy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ export class BlockDragStrategy implements IDragStrategy {
380380

381381
if (this.moveMode === MoveMode.CONSTRAINED) {
382382
showUnconstrainedMoveHint(this.workspace, true);
383+
this.workspace.getAudioManager().playErrorBeep();
383384
}
384385
}
385386
}

packages/blockly/core/workspace_audio.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ export class WorkspaceAudio {
138138
oscillator.stop(this.context.currentTime + duration);
139139
}
140140

141+
/**
142+
* Plays a standard error beep.
143+
*/
144+
async playErrorBeep() {
145+
return this.beep(260);
146+
}
147+
141148
/**
142149
* Returns whether or not playing sounds is currently allowed.
143150
*

packages/blockly/tests/mocha/keyboard_movement_test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ suite('Keyboard-driven movement', function () {
534534
suite('in constrained mode', function () {
535535
test('prompts to use unconstrained mode when no destinations are available', function () {
536536
const toastSpy = sinon.spy(Blockly.Toast, 'show');
537+
const beepSpy = sinon.spy(this.workspace.getAudioManager(), 'beep');
537538
Blockly.getFocusManager().focusNode(this.element);
538539
const originalBounds = this.element.getBoundingRectangle();
539540
startMove(this.workspace);
@@ -547,6 +548,8 @@ suite('Keyboard-driven movement', function () {
547548
? 'Hold ⌘ Command and use arrow keys to move freely, then Enter to accept the position'
548549
: 'Hold Ctrl and use arrow keys to move freely, then Enter to accept the position',
549550
);
551+
sinon.assert.calledOnce(beepSpy);
552+
beepSpy.restore();
550553
toastSpy.restore();
551554
});
552555

0 commit comments

Comments
 (0)