Skip to content
Open
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
1 change: 1 addition & 0 deletions packages/blockly/core/dragging/block_drag_strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ export class BlockDragStrategy implements IDragStrategy {
recordUndo: true,
},
) as BlockSvg;
newBlock.setDragging(true);
eventUtils.setRecordUndo(false);
newBlock.render();
this.positionNewBlock(this.block, newBlock);
Expand Down
5 changes: 4 additions & 1 deletion packages/blockly/core/dropdowndiv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ export function createDom() {
content,
'keydown',
null,
common.globalShortcutHandler,
(e: KeyboardEvent) => {
common.globalShortcutHandler(e);
e.stopPropagation();
},
);

arrow = document.createElement('div');
Expand Down
5 changes: 4 additions & 1 deletion packages/blockly/core/widgetdiv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ export function createDom() {
containerDiv,
'keydown',
null,
common.globalShortcutHandler,
(e: KeyboardEvent) => {
common.globalShortcutHandler(e);
e.stopPropagation();
},
);

container.appendChild(containerDiv);
Expand Down
16 changes: 16 additions & 0 deletions packages/blockly/tests/mocha/shortcut_items_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1885,6 +1885,22 @@ suite('Keyboard Shortcut Items', function () {
this.workspace.getInjectionDiv().dispatchEvent(event);
assert.equal(this.workspace.getTopComments().length, 1);
});

test('Is idempotent when a contextual menu is open', function () {
const comment = this.workspace.newComment();
comment.setText('Hello');
Blockly.getFocusManager().focusNode(comment);
comment.showContextMenu();
assert.equal(this.workspace.getTopComments().length, 1);
const event = createKeyDownEvent(Blockly.utils.KeyCodes.D);
// The WidgetDiv (used by the dropdown menu) registers the global shortcut
// handler for its own div, since it may live outside of the injection
// div. Ensure that it also prevents event bubbling to the main shortcut
// handler, which could cause shortcuts like Duplicate to be invoked
// multiple times from one keypress. See #10250.
Blockly.WidgetDiv.getDiv().dispatchEvent(event);
assert.equal(this.workspace.getTopComments().length, 2);
});
});

suite('Clean up workspace (C)', function () {
Expand Down
1 change: 1 addition & 0 deletions packages/blockly/tests/mocha/test_helpers/user_input.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export function dispatchPointerEvent(target, type, properties) {
export function createKeyDownEvent(keyCode, modifiers) {
const event = {
keyCode: keyCode,
bubbles: true,
};
if (modifiers && modifiers.length > 0) {
event.altKey = modifiers.includes(KeyCodes.ALT);
Expand Down