GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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
Filter options
  • src
    • blocks
      • procedures.js
    • index.js
    • scratch_block_paster.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/blocks/procedures.js‎

Copy file name to clipboardExpand all lines: src/blocks/procedures.js
+3-5Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,19 @@ class DuplicateOnDragDraggable {
3737
startDrag(e) {
3838
const data = this.block.toCopyData();
3939
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);
4341
}
4442

4543
drag(e) {
4644
this.block.workspace
4745
.getGesture(e)
4846
.getCurrentDragger()
4947
.setDraggable(this.copy);
50-
this.baseStrat.drag(e);
48+
this.copy.drag(e);
5149
}
5250

5351
endDrag(e) {
54-
this.baseStrat?.endDrag(e);
52+
this.copy?.endDrag(e);
5553
}
5654

5755
revertDrag(e) {
Collapse file

‎src/index.js‎

Copy file name to clipboardExpand all lines: src/index.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import { registerFieldVariableGetter } from "./fields/field_variable_getter.js";
6161
import { registerFieldVariable } from "./fields/field_variable.js";
6262
import { registerFieldVerticalSeparator } from "./fields/field_vertical_separator.js";
6363
import { registerRecyclableBlockFlyoutInflater } from "./recyclable_block_flyout_inflater.js";
64+
import { registerScratchBlockPaster } from "./scratch_block_paster.js";
6465
import { registerStatusIndicatorLabelFlyoutInflater } from "./status_indicator_label_flyout_inflater.js";
6566
import { registerScratchContinuousCategory } from "./scratch_continuous_category.js";
6667

@@ -94,6 +95,7 @@ export function inject(container, options) {
9495
registerFieldVariable();
9596
registerFieldVerticalSeparator();
9697
registerRecyclableBlockFlyoutInflater();
98+
registerScratchBlockPaster();
9799
registerStatusIndicatorLabelFlyoutInflater();
98100
registerScratchContinuousCategory();
99101

Collapse file

‎src/scratch_block_paster.js‎

Copy file name to clipboard
+46Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.