File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -154,3 +154,27 @@ function deleteNext(deleteList: Blockly.BlockSvg[], eventGroup?: string) {
154154 }
155155 Blockly . Events . setGroup ( false ) ;
156156}
157+
158+ /**
159+ * Registers a block duplicate option that duplicates the selected block and
160+ * all subsequent blocks in the stack.
161+ */
162+ export function registerDuplicateBlock ( ) {
163+ const original =
164+ Blockly . ContextMenuRegistry . registry . getItem ( "blockDuplicate" ) ;
165+ const duplicateOption = {
166+ displayText : original . displayText ,
167+ preconditionFn : original . preconditionFn ,
168+ callback ( scope : Blockly . ContextMenuRegistry . Scope ) {
169+ if ( ! scope . block ) return ;
170+ const data = scope . block . toCopyData ( true ) ;
171+ if ( ! data ) return ;
172+ Blockly . clipboard . paste ( data , scope . block . workspace ) ;
173+ } ,
174+ scopeType : original . scopeType ,
175+ id : original . id ,
176+ weight : original . weight ,
177+ } ;
178+ Blockly . ContextMenuRegistry . registry . unregister ( duplicateOption . id ) ;
179+ Blockly . ContextMenuRegistry . registry . register ( duplicateOption ) ;
180+ }
Original file line number Diff line number Diff line change @@ -129,6 +129,7 @@ Blockly.ContextMenuRegistry.registry.unregister("blockInline");
129129Blockly . ContextMenuItems . registerCommentOptions ( ) ;
130130Blockly . ContextMenuRegistry . registry . unregister ( "blockDelete" ) ;
131131contextMenuItems . registerDeleteBlock ( ) ;
132+ contextMenuItems . registerDuplicateBlock ( ) ;
132133Blockly . ContextMenuRegistry . registry . unregister ( "workspaceDelete" ) ;
133134contextMenuItems . registerDeleteAll ( ) ;
134135Blockly . comments . CommentView . defaultCommentSize = new Blockly . utils . Size (
You can’t perform that action at this time.
0 commit comments