Skip to content
Merged
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
24 changes: 23 additions & 1 deletion src/actions/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
*/

import {
ASTNode,
ContextMenuRegistry,
Gesture,
ShortcutRegistry,
Events,
utils as blocklyUtils,
clipboard,
ICopyData,
} from 'blockly';
import * as Constants from '../constants';
Expand Down Expand Up @@ -356,7 +359,26 @@ export class Clipboard {
const pasteWorkspace = this.copyWorkspace.isFlyout
? workspace
: this.copyWorkspace;
return this.navigation.paste(this.copyData, pasteWorkspace);

// Do this before clipoard.paste due to cursor/focus workaround in getCurNode.
const targetNode = pasteWorkspace.getCursor()?.getCurNode();

Events.setGroup(true);
const block = clipboard.paste(this.copyData, pasteWorkspace) as BlockSvg;
if (block) {
if (targetNode) {
this.navigation.tryToConnectNodes(
pasteWorkspace,
targetNode,
ASTNode.createBlockNode(block)!,
);
}
this.navigation.removeMark(pasteWorkspace);
Events.setGroup(false);
return true;
}
Events.setGroup(false);
return false;
}

/**
Expand Down
32 changes: 0 additions & 32 deletions src/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1365,38 +1365,6 @@ export class Navigation {
return true;
}

/**
* Pastes the copied block to the marked location if possible or
* onto the workspace otherwise.
*
* @param copyData The data to paste into the workspace.
* @param workspace The workspace to paste the data into.
* @returns True if the paste was sucessful, false otherwise.
*/
paste(copyData: Blockly.ICopyData, workspace: Blockly.WorkspaceSvg): boolean {
// Do this before clipoard.paste due to cursor/focus workaround in getCurNode.
const targetNode = workspace.getCursor()?.getCurNode();

Blockly.Events.setGroup(true);
const block = Blockly.clipboard.paste(
copyData,
workspace,
) as Blockly.BlockSvg;
if (block) {
if (targetNode) {
this.tryToConnectNodes(
workspace,
targetNode,
Blockly.ASTNode.createBlockNode(block)!,
);
}
this.removeMark(workspace);
return true;
}
Blockly.Events.setGroup(false);
return false;
}

/**
* Triggers a flyout button's callback.
*
Expand Down