From 97cfd951c32c7e4ffb2ad4ea6dced46b2346a36a Mon Sep 17 00:00:00 2001 From: sussy layers dev <72522395+jwklong@users.noreply.github.com> Date: Sun, 8 Dec 2024 17:14:20 +0000 Subject: [PATCH] contextmenu.blockcollapseoption --- core/contextmenu.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/core/contextmenu.js b/core/contextmenu.js index 2a80ebe2bc..46e12160c6 100644 --- a/core/contextmenu.js +++ b/core/contextmenu.js @@ -286,6 +286,31 @@ Blockly.ContextMenu.blockDuplicateOption = function(block, event) { return duplicateOption; }; +/** + * Make a context menu option for adding or removing comments on the current + * block. + * @param {!Blockly.BlockSvg} block The block where the right-click originated. + * @return {!Object} A menu option, containing text, enabled, and a callback. + * @package + */ +Blockly.ContextMenu.blockCollapseOption = function(block) { + var commentOption = { + enabled: true + }; + if (block.isCollapsed()) { + commentOption.text = "Expand block"; + commentOption.callback = function() { + block.setCollapsed(false) + }; + } else { + commentOption.text = "Collapse block"; + commentOption.callback = function() { + block.setCollapsed(true) + }; + } + return commentOption; +}; + /** * Make a context menu option for adding or removing comments on the current * block.