How to add Undo & Redo on Blockly Workspace

1,042 views
Skip to first unread message

shinu sam

unread,
Jul 23, 2018, 2:23:23 AM7/23/18
to Blockly
Hello,

     This forum helps me to solve problems of my project related to blockly.  I am thankful to all members who are actively participating in this forum. Today I am trying to add Undo, Redo, Repeat properties in Blockly Workspace. But i am not able to create it. If anyone know please reply me.  Also i would like to know that  how to create  repeltion on blockly blocks. Kindly waiting for your valuable replies. 

Thank You.




Neil Fraser

unread,
Jul 23, 2018, 10:50:26 AM7/23/18
to blo...@googlegroups.com
Calling this will undo one step:
  Blockly.mainWorkspace.undo(false);
Calling this will redo one step:
  Blockly.mainWorkspace.undo(true);

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

shinu sam

unread,
Jul 24, 2018, 1:38:44 AM7/24/18
to Blockly

Thank You Sir,
  
                        Unfortunately this code is not working.


<script>
var workspace = Blockly.inject('blocklyDiv',
{ toolbox: document.getElementById('toolbox')/*,allowUndoRedo: true*/ });
var defaultBlocks = document.getElementById('blocklyDefault');
Blockly.Xml.domToWorkspace(defaultBlocks, workspace);
Blockly.mainWorkspace.undo(true);
Blockly.mainWorkspace.undo(false);

</script>


 Please sugggest a solution for this  Sir. Kindly waiting for reply.


Anschke

unread,
Jul 26, 2018, 10:02:53 AM7/26/18
to Blockly
Hi sinu sam,

I am not one of the Blockly professionals, but I give it a try to answer your question.
To make it work you gotta bind the two functions Neil suggested to e.g. Buttons - just calling them once on an empty workspace will of course have no effect.

Just put them into js functions like
function undoAction(){
Blockly.mainWorkspace.undo(false);
}
function redoAction(){
Blockly.mainWorkspace.undo(true);
}

and then bind these to the onclick-call of e.g. two Buttons defined in your .html file or application. When clicking them the main workspace will now perform the undo/redo actions.

I have to admit that these are somehow misleading as they more look like setters than function calls if one is not that familiar with blockly. 

Hope this answer helps to solve your problem!
Reply all
Reply to author
Forward
0 new messages