mirror of
https://github.com/google/blockly.git
synced 2026-01-08 01:20:12 +01:00
fix: Paste blocks copied from a mutator into the mutator. (#8719)
This commit is contained in:
@@ -83,7 +83,9 @@ function pasteFromData<T extends ICopyData>(
|
||||
workspace: WorkspaceSvg,
|
||||
coordinate?: Coordinate,
|
||||
): ICopyable<T> | null {
|
||||
workspace = workspace.getRootWorkspace() ?? workspace;
|
||||
workspace = workspace.isMutator
|
||||
? workspace
|
||||
: (workspace.getRootWorkspace() ?? workspace);
|
||||
return (globalRegistry
|
||||
.getObject(globalRegistry.Type.PASTER, copyData.paster, false)
|
||||
?.paste(copyData, workspace, coordinate) ?? null) as ICopyable<T> | null;
|
||||
|
||||
@@ -18,7 +18,7 @@ import {KeyboardShortcut, ShortcutRegistry} from './shortcut_registry.js';
|
||||
import {Coordinate} from './utils/coordinate.js';
|
||||
import {KeyCodes} from './utils/keycodes.js';
|
||||
import {Rect} from './utils/rect.js';
|
||||
import type {WorkspaceSvg} from './workspace_svg.js';
|
||||
import {WorkspaceSvg} from './workspace_svg.js';
|
||||
|
||||
/**
|
||||
* Object holding the names of the default shortcut items.
|
||||
@@ -131,7 +131,10 @@ export function registerCopy() {
|
||||
const selected = common.getSelected();
|
||||
if (!selected || !isCopyable(selected)) return false;
|
||||
copyData = selected.toCopyData();
|
||||
copyWorkspace = workspace;
|
||||
copyWorkspace =
|
||||
selected.workspace instanceof WorkspaceSvg
|
||||
? selected.workspace
|
||||
: workspace;
|
||||
copyCoords = isDraggable(selected)
|
||||
? selected.getRelativeToSurfaceXY()
|
||||
: null;
|
||||
|
||||
@@ -61,6 +61,30 @@ suite('Clipboard', function () {
|
||||
);
|
||||
});
|
||||
|
||||
test('copied from a mutator pastes them into the mutator', async function () {
|
||||
const block = Blockly.serialization.blocks.append(
|
||||
{
|
||||
'type': 'controls_if',
|
||||
'id': 'blockId',
|
||||
'extraState': {
|
||||
'elseIfCount': 1,
|
||||
},
|
||||
},
|
||||
this.workspace,
|
||||
);
|
||||
const mutatorIcon = block.getIcon(Blockly.icons.IconType.MUTATOR);
|
||||
await mutatorIcon.setBubbleVisible(true);
|
||||
const mutatorWorkspace = mutatorIcon.getWorkspace();
|
||||
const elseIf = mutatorWorkspace.getBlocksByType('controls_if_elseif')[0];
|
||||
assert.notEqual(elseIf, undefined);
|
||||
assert.lengthOf(mutatorWorkspace.getAllBlocks(), 2);
|
||||
assert.lengthOf(this.workspace.getAllBlocks(), 1);
|
||||
const data = elseIf.toCopyData();
|
||||
Blockly.clipboard.paste(data, mutatorWorkspace);
|
||||
assert.lengthOf(mutatorWorkspace.getAllBlocks(), 3);
|
||||
assert.lengthOf(this.workspace.getAllBlocks(), 1);
|
||||
});
|
||||
|
||||
suite('pasted blocks are placed in unambiguous locations', function () {
|
||||
test('pasted blocks are bumped to not overlap', function () {
|
||||
const block = Blockly.serialization.blocks.append(
|
||||
|
||||
Reference in New Issue
Block a user