Merge pull request #33781 from sokumon/duplicate-block

feat(Workspace): add ability to duplicate the block
This commit is contained in:
Soham Kulkarni 2025-08-25 12:34:10 +05:30 committed by GitHub
commit f0e9ea7f36
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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");
}
}