diff --git a/frappe/public/js/frappe/views/workspace/blocks/block.js b/frappe/public/js/frappe/views/workspace/blocks/block.js index cc105291f3..f1963a3f59 100644 --- a/frappe/public/js/frappe/views/workspace/blocks/block.js +++ b/frappe/public/js/frappe/views/workspace/blocks/block.js @@ -186,6 +186,12 @@ export default class Block { icon: frappe.utils.icon("down-arrow", "sm"), action: () => this.move_block("down"), }, + { + label: "Duplicate", + title: "Duplicate", + icon: frappe.utils.icon("copy", "sm"), + action: () => this.duplicate_block(), + }, ]; let $widget_control = $(this.wrapper).find(".widget-control"); @@ -337,4 +343,17 @@ export default class Block { let new_index = current_index + (direction == "down" ? 1 : -1); this.api.blocks.move(new_index, current_index); } + + duplicate_block() { + const current_block_index = this.api.blocks.getCurrentBlockIndex(); + const current_block = this.api.blocks.getBlockByIndex(current_block_index); + + if (!current_block) return; + + const type = current_block.name; + const data = this.data; + + this.api.blocks.insert(type, data, null, current_block_index + 1, true); + this.api.caret.setToBlock(current_block_index + 1, "end"); + } }