-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix bug that could cause duplicated procedure argument blocks to…
… create more duplicates on drag (#217)
- Loading branch information
Showing
3 changed files
with
51 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* @license | ||
* Copyright 2024 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import * as Blockly from "blockly/core"; | ||
|
||
/** | ||
* Class responsible for handling the pasting of copied blocks. | ||
*/ | ||
class ScratchBlockPaster extends Blockly.clipboard.BlockPaster { | ||
/** | ||
* Deserializes the given block data onto the workspace. | ||
* | ||
* @param {!Blockly.clipboard.BlockCopyData} copyData The serialized block | ||
* state to create a copy of on the workspace. | ||
* @param {!Blockly.WorkspaceSvg} workspace The workspace to paste the block | ||
* onto. | ||
* @param {?Blockly.utils.Coordinate} coordinate The location to paste the | ||
* block. | ||
*/ | ||
paste(copyData, workspace, coordinate) { | ||
const block = super.paste(copyData, workspace, coordinate); | ||
if ( | ||
block?.type === "argument_reporter_boolean" || | ||
block?.type === "argument_reporter_string_number" | ||
) { | ||
block.setDragStrategy(new Blockly.dragging.BlockDragStrategy(block)); | ||
} | ||
|
||
return block; | ||
} | ||
} | ||
|
||
/** | ||
* Unregisters the default block paster and registers ScratchBlockPaster in its | ||
* place. | ||
*/ | ||
export function registerScratchBlockPaster() { | ||
Blockly.clipboard.registry.unregister(ScratchBlockPaster.TYPE); | ||
Blockly.clipboard.registry.register( | ||
ScratchBlockPaster.TYPE, | ||
new ScratchBlockPaster() | ||
); | ||
} |