Skip to content

Commit

Permalink
fix: undo/redo for auto disabling if-return blocks (google#6018)
Browse files Browse the repository at this point in the history
* fix: undo/redo for auto disabling if-return blocks

* fix: update inline docs
  • Loading branch information
BeksOmega authored Mar 23, 2022
1 parent c430800 commit c7a359a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion blocks/loops.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ const CONTROL_FLOW_IN_LOOP_CHECK_MIXIN = {
/**
* Called whenever anything on the workspace changes.
* Add warning if this flow block is not nested inside a loop.
* @param {!AbstractEvent} e Change event.
* @param {!AbstractEvent} e Move event.
* @this {Block}
*/
onchange: function(e) {
Expand Down
20 changes: 11 additions & 9 deletions blocks/procedures.js
Original file line number Diff line number Diff line change
Expand Up @@ -1139,11 +1139,12 @@ blocks['procedures_ifreturn'] = {
/**
* Called whenever anything on the workspace changes.
* Add warning if this flow block is not nested inside a loop.
* @param {!AbstractEvent} _e Change event.
* @param {!AbstractEvent} e Move event.
* @this {Block}
*/
onchange: function(_e) {
if (this.workspace.isDragging && this.workspace.isDragging()) {
onchange: function(e) {
if (this.workspace.isDragging && this.workspace.isDragging() ||
e.type !== Events.BLOCK_MOVE) {
return; // Don't change state at the start of a drag.
}
let legal = false;
Expand Down Expand Up @@ -1171,14 +1172,15 @@ blocks['procedures_ifreturn'] = {
this.hasReturnValue_ = true;
}
this.setWarningText(null);
if (!this.isInFlyout) {
this.setEnabled(true);
}
} else {
this.setWarningText(Msg['PROCEDURES_IFRETURN_WARNING']);
if (!this.isInFlyout && !this.getInheritedDisabled()) {
this.setEnabled(false);
}
}
if (!this.isInFlyout) {
const group = Events.getGroup();
// Makes it so the move and the disable event get undone together.
Events.setGroup(e.group);
this.setEnabled(legal);
Events.setGroup(group);
}
},
/**
Expand Down

0 comments on commit c7a359a

Please sign in to comment.