Merge pull request #33781 from sokumon/duplicate-block
feat(Workspace): add ability to duplicate the block
This commit is contained in:
commit
f0e9ea7f36
1 changed files with 19 additions and 0 deletions
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue