Skip to content

Commit 0ae1b73

Browse files
chore: move paste implementation into clipboard.ts (#283)
* chore: move paste implementation into clipboard.ts * fix: correctly set event group
1 parent 8695b02 commit 0ae1b73

File tree

2 files changed

+23
-33
lines changed

2 files changed

+23
-33
lines changed

src/actions/clipboard.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
*/
66

77
import {
8+
ASTNode,
89
ContextMenuRegistry,
910
Gesture,
1011
ShortcutRegistry,
12+
Events,
1113
utils as blocklyUtils,
14+
clipboard,
1215
ICopyData,
1316
} from 'blockly';
1417
import * as Constants from '../constants';
@@ -356,7 +359,26 @@ export class Clipboard {
356359
const pasteWorkspace = this.copyWorkspace.isFlyout
357360
? workspace
358361
: this.copyWorkspace;
359-
return this.navigation.paste(this.copyData, pasteWorkspace);
362+
363+
// Do this before clipoard.paste due to cursor/focus workaround in getCurNode.
364+
const targetNode = pasteWorkspace.getCursor()?.getCurNode();
365+
366+
Events.setGroup(true);
367+
const block = clipboard.paste(this.copyData, pasteWorkspace) as BlockSvg;
368+
if (block) {
369+
if (targetNode) {
370+
this.navigation.tryToConnectNodes(
371+
pasteWorkspace,
372+
targetNode,
373+
ASTNode.createBlockNode(block)!,
374+
);
375+
}
376+
this.navigation.removeMark(pasteWorkspace);
377+
Events.setGroup(false);
378+
return true;
379+
}
380+
Events.setGroup(false);
381+
return false;
360382
}
361383

362384
/**

src/navigation.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,38 +1356,6 @@ export class Navigation {
13561356
return true;
13571357
}
13581358

1359-
/**
1360-
* Pastes the copied block to the marked location if possible or
1361-
* onto the workspace otherwise.
1362-
*
1363-
* @param copyData The data to paste into the workspace.
1364-
* @param workspace The workspace to paste the data into.
1365-
* @returns True if the paste was sucessful, false otherwise.
1366-
*/
1367-
paste(copyData: Blockly.ICopyData, workspace: Blockly.WorkspaceSvg): boolean {
1368-
// Do this before clipoard.paste due to cursor/focus workaround in getCurNode.
1369-
const targetNode = workspace.getCursor()?.getCurNode();
1370-
1371-
Blockly.Events.setGroup(true);
1372-
const block = Blockly.clipboard.paste(
1373-
copyData,
1374-
workspace,
1375-
) as Blockly.BlockSvg;
1376-
if (block) {
1377-
if (targetNode) {
1378-
this.tryToConnectNodes(
1379-
workspace,
1380-
targetNode,
1381-
Blockly.ASTNode.createBlockNode(block)!,
1382-
);
1383-
}
1384-
this.removeMark(workspace);
1385-
return true;
1386-
}
1387-
Blockly.Events.setGroup(false);
1388-
return false;
1389-
}
1390-
13911359
/**
13921360
* Triggers a flyout button's callback.
13931361
*

0 commit comments

Comments
 (0)