GeezerVison is showing github.com — fix: fix bug that could cause duplicated procedure argument blocks to… · scratchfoundation/scratch-blocks@6a1c8a9
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/blocks/procedures.js +3-5Lines changed: 3 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -37,21 +37,19 @@ class DuplicateOnDragDraggable { |
37 | 37 | startDrag(e) { |
38 | 38 | const data = this.block.toCopyData(); |
39 | 39 | this.copy = Blockly.clipboard.paste(data, this.block.workspace); |
40 | | - this.baseStrat = new Blockly.dragging.BlockDragStrategy(this.copy); |
41 | | - this.copy.setDragStrategy(this.baseStrat); |
42 | | - this.baseStrat.startDrag(e); |
| 40 | + this.copy.startDrag(e); |
43 | 41 | } |
44 | 42 |
|
45 | 43 | drag(e) { |
46 | 44 | this.block.workspace |
47 | 45 | .getGesture(e) |
48 | 46 | .getCurrentDragger() |
49 | 47 | .setDraggable(this.copy); |
50 | | - this.baseStrat.drag(e); |
| 48 | + this.copy.drag(e); |
51 | 49 | } |
52 | 50 |
|
53 | 51 | endDrag(e) { |
54 | | - this.baseStrat?.endDrag(e); |
| 52 | + this.copy?.endDrag(e); |
55 | 53 | } |
56 | 54 |
|
57 | 55 | revertDrag(e) { |
|
Collapse file
Copy file name to clipboardExpand all lines: src/index.js +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -61,6 +61,7 @@ import { registerFieldVariableGetter } from "./fields/field_variable_getter.js"; |
61 | 61 | import { registerFieldVariable } from "./fields/field_variable.js"; |
62 | 62 | import { registerFieldVerticalSeparator } from "./fields/field_vertical_separator.js"; |
63 | 63 | import { registerRecyclableBlockFlyoutInflater } from "./recyclable_block_flyout_inflater.js"; |
| 64 | +import { registerScratchBlockPaster } from "./scratch_block_paster.js"; |
64 | 65 | import { registerStatusIndicatorLabelFlyoutInflater } from "./status_indicator_label_flyout_inflater.js"; |
65 | 66 | import { registerScratchContinuousCategory } from "./scratch_continuous_category.js"; |
66 | 67 |
|
@@ -94,6 +95,7 @@ export function inject(container, options) { |
94 | 95 | registerFieldVariable(); |
95 | 96 | registerFieldVerticalSeparator(); |
96 | 97 | registerRecyclableBlockFlyoutInflater(); |
| 98 | + registerScratchBlockPaster(); |
97 | 99 | registerStatusIndicatorLabelFlyoutInflater(); |
98 | 100 | registerScratchContinuousCategory(); |
99 | 101 |
|
|
Collapse file
Copy file name to clipboard +46Lines changed: 46 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2024 Google LLC |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +import * as Blockly from "blockly/core"; |
| 8 | + |
| 9 | +/** |
| 10 | + * Class responsible for handling the pasting of copied blocks. |
| 11 | + */ |
| 12 | +class ScratchBlockPaster extends Blockly.clipboard.BlockPaster { |
| 13 | + /** |
| 14 | + * Deserializes the given block data onto the workspace. |
| 15 | + * |
| 16 | + * @param {!Blockly.clipboard.BlockCopyData} copyData The serialized block |
| 17 | + * state to create a copy of on the workspace. |
| 18 | + * @param {!Blockly.WorkspaceSvg} workspace The workspace to paste the block |
| 19 | + * onto. |
| 20 | + * @param {?Blockly.utils.Coordinate} coordinate The location to paste the |
| 21 | + * block. |
| 22 | + */ |
| 23 | + paste(copyData, workspace, coordinate) { |
| 24 | + const block = super.paste(copyData, workspace, coordinate); |
| 25 | + if ( |
| 26 | + block?.type === "argument_reporter_boolean" || |
| 27 | + block?.type === "argument_reporter_string_number" |
| 28 | + ) { |
| 29 | + block.setDragStrategy(new Blockly.dragging.BlockDragStrategy(block)); |
| 30 | + } |
| 31 | + |
| 32 | + return block; |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +/** |
| 37 | + * Unregisters the default block paster and registers ScratchBlockPaster in its |
| 38 | + * place. |
| 39 | + */ |
| 40 | +export function registerScratchBlockPaster() { |
| 41 | + Blockly.clipboard.registry.unregister(ScratchBlockPaster.TYPE); |
| 42 | + Blockly.clipboard.registry.register( |
| 43 | + ScratchBlockPaster.TYPE, |
| 44 | + new ScratchBlockPaster() |
| 45 | + ); |
| 46 | +} |