Skip to content

Commit f48256e

Browse files
rachel-fenichelgonfunko
authored andcommitted
chore: move paste implementation into clipboard.ts (#283)
* chore: move paste implementation into clipboard.ts * fix: correctly set event group
1 parent 1205d2c commit f48256e

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
@@ -1358,38 +1358,6 @@ export class Navigation {
13581358
return true;
13591359
}
13601360

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

0 commit comments

Comments
 (0)