Disable events while workspace comment is getting created and moved. Fire CommentCreate event when that is done.

This commit is contained in:
Karishma Chadha 2018-06-01 17:53:22 -04:00
parent 3d3b8f3427
commit b69f6869bc

View file

@ -455,6 +455,11 @@ Blockly.ContextMenu.workspaceCommentOption = function(ws, e) {
// Helper function to create and position a comment correctly based on the
// location of the mouse event.
var addWsComment = function() {
// Disable events while this comment is getting created
// so that we can fire a single create event for this comment
// at the end (instead of CommentCreate followed by CommentMove,
// which results in unexpected undo behavior).
if (Blockly.Events.isEnabled()) Blockly.Events.disable();
var comment = new Blockly.WorkspaceCommentSvg(
ws, Blockly.Msg.WORKSPACE_COMMENT_DEFAULT_TEXT,
Blockly.WorkspaceCommentSvg.DEFAULT_SIZE,
@ -490,6 +495,8 @@ Blockly.ContextMenu.workspaceCommentOption = function(ws, e) {
comment.render(false);
comment.select();
}
Blockly.Events.enable();
Blockly.WorkspaceComment.fireCreateEvent(comment);
};
var wsCommentOption = {enabled: true};