scratch-blocks 2.0.6 → 2.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,4 +11,14 @@ export declare function registerDeleteAll(): void;
11
11
  * all subsequent blocks in the stack.
12
12
  */
13
13
  export declare function registerDuplicateBlock(): void;
14
+ /**
15
+ * Overrides the copy keyboard shortcut so that it includes subsequent blocks
16
+ * in the stack (via the next connection) when copying a block.
17
+ */
18
+ export declare function registerCopyShortcut(): void;
19
+ /**
20
+ * Overrides the cut keyboard shortcut so that it includes subsequent blocks
21
+ * in the stack (via the next connection) when cutting a block.
22
+ */
23
+ export declare function registerCutShortcut(): void;
14
24
  //# sourceMappingURL=context_menu_items.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"context_menu_items.d.ts","sourceRoot":"","sources":["../../../src/context_menu_items.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,wBAAgB,mBAAmB,SAwBlC;AAgBD;;GAEG;AACH,wBAAgB,iBAAiB,SA2ChC;AAsCD;;;GAGG;AACH,wBAAgB,sBAAsB,SAiBrC"}
1
+ {"version":3,"file":"context_menu_items.d.ts","sourceRoot":"","sources":["../../../src/context_menu_items.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,wBAAgB,mBAAmB,SAwBlC;AAgBD;;GAEG;AACH,wBAAgB,iBAAiB,SA2ChC;AAsCD;;;GAGG;AACH,wBAAgB,sBAAsB,SAiBrC;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,SAsBnC;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,SAuBlC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scratch-blocks",
3
- "version": "2.0.6",
3
+ "version": "2.0.7",
4
4
  "description": "Scratch Blocks is a library for building creative computing interfaces.",
5
5
  "author": "Massachusetts Institute of Technology",
6
6
  "license": "Apache-2.0",
@@ -153,3 +153,60 @@ export function registerDuplicateBlock() {
153
153
  Blockly.ContextMenuRegistry.registry.unregister(duplicateOption.id)
154
154
  Blockly.ContextMenuRegistry.registry.register(duplicateOption)
155
155
  }
156
+
157
+ /**
158
+ * Overrides the copy keyboard shortcut so that it includes subsequent blocks
159
+ * in the stack (via the next connection) when copying a block.
160
+ */
161
+ export function registerCopyShortcut() {
162
+ const original = Blockly.ShortcutRegistry.registry.getRegistry()[Blockly.ShortcutItems.names.COPY]
163
+ Blockly.ShortcutRegistry.registry.register(
164
+ {
165
+ ...original,
166
+ callback(workspace, e, shortcut, scope) {
167
+ const focused = scope.focusedNode
168
+ if (focused instanceof Blockly.BlockSvg && !focused.isInFlyout) {
169
+ e.preventDefault()
170
+ const copyData = focused.toCopyData(true)
171
+ if (copyData) {
172
+ Blockly.clipboard.setLastCopiedData(copyData)
173
+ Blockly.clipboard.setLastCopiedWorkspace(focused.workspace)
174
+ Blockly.clipboard.setLastCopiedLocation(focused.getRelativeToSurfaceXY())
175
+ return true
176
+ }
177
+ }
178
+ return original.callback?.(workspace, e, shortcut, scope) ?? false
179
+ },
180
+ },
181
+ true,
182
+ )
183
+ }
184
+
185
+ /**
186
+ * Overrides the cut keyboard shortcut so that it includes subsequent blocks
187
+ * in the stack (via the next connection) when cutting a block.
188
+ */
189
+ export function registerCutShortcut() {
190
+ const original = Blockly.ShortcutRegistry.registry.getRegistry()[Blockly.ShortcutItems.names.CUT]
191
+ Blockly.ShortcutRegistry.registry.register(
192
+ {
193
+ ...original,
194
+ callback(workspace, e, shortcut, scope) {
195
+ const focused = scope.focusedNode
196
+ if (focused instanceof Blockly.BlockSvg && !focused.isInFlyout) {
197
+ e.preventDefault()
198
+ const copyData = focused.toCopyData(true)
199
+ if (copyData && focused.isDeletable()) {
200
+ Blockly.clipboard.setLastCopiedData(copyData)
201
+ Blockly.clipboard.setLastCopiedWorkspace(focused.workspace)
202
+ Blockly.clipboard.setLastCopiedLocation(focused.getRelativeToSurfaceXY())
203
+ focused.checkAndDelete()
204
+ return true
205
+ }
206
+ }
207
+ return original.callback?.(workspace, e, shortcut, scope) ?? false
208
+ },
209
+ },
210
+ true,
211
+ )
212
+ }
package/src/index.ts CHANGED
@@ -154,6 +154,8 @@ Blockly.ContextMenuItems.registerCommentOptions()
154
154
  Blockly.ContextMenuRegistry.registry.unregister('blockDelete')
155
155
  contextMenuItems.registerDeleteBlock()
156
156
  contextMenuItems.registerDuplicateBlock()
157
+ contextMenuItems.registerCopyShortcut()
158
+ contextMenuItems.registerCutShortcut()
157
159
  Blockly.ContextMenuRegistry.registry.unregister('workspaceDelete')
158
160
  contextMenuItems.registerDeleteAll()
159
161
  Blockly.comments.CommentView.defaultCommentSize = new Blockly.utils.Size(200, 200)