Skip to content

Commit

Permalink
fix: Don't record undo events for enable/disable
Browse files Browse the repository at this point in the history
There's no need to record and replay these events since the change will happen automatically anyway.

Resolves #7951

# Conflicts:
#	blocks/loops.ts
#	blocks/procedures.ts
  • Loading branch information
NeilFraser committed Apr 29, 2024
1 parent 19fa491 commit 955fbe7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
21 changes: 13 additions & 8 deletions blocks/loops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
createBlockDefinitionsFromJsonArray,
defineBlocks,
} from '../core/common.js';
import * as eventUtils from '../core/events/utils.js';
import '../core/field_dropdown.js';
import '../core/field_label.js';
import '../core/field_number.js';
Expand Down Expand Up @@ -381,15 +382,19 @@ const CONTROL_FLOW_IN_LOOP_CHECK_MIXIN = {
this.setWarningText(
enabled ? null : Msg['CONTROLS_FLOW_STATEMENTS_WARNING'],
);

if (!this.isInFlyout) {
const group = Events.getGroup();
// Makes it so the move and the disable event get undone together.
Events.setGroup(e.group);
this.setDisabledReason(
!enabled,
CONTROL_FLOW_NOT_IN_LOOP_DISABLED_REASON,
);
Events.setGroup(group);
try {
// There is no need to record the enable/disable change on the undo/redo
// list since the change will be automatically recreated when replayed.
eventUtils.setRecordUndo(false);
this.setDisabledReason(
!enabled,
CONTROL_FLOW_NOT_IN_LOOP_DISABLED_REASON,
);
} finally {
eventUtils.setRecordUndo(true);
}
}
},
};
Expand Down
15 changes: 10 additions & 5 deletions blocks/procedures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import type {
ContextMenuOption,
LegacyContextMenuOption,
} from '../core/contextmenu_registry.js';
import * as eventUtils from '../core/events/utils.js';
import {FieldCheckbox} from '../core/field_checkbox.js';
import {FieldLabel} from '../core/field_label.js';
import {FieldTextInput} from '../core/field_textinput.js';
Expand Down Expand Up @@ -1329,12 +1330,16 @@ const PROCEDURES_IFRETURN = {
} else {
this.setWarningText(Msg['PROCEDURES_IFRETURN_WARNING']);
}

if (!this.isInFlyout) {
const group = Events.getGroup();
// Makes it so the move and the disable event get undone together.
Events.setGroup(e.group);
this.setDisabledReason(!legal, UNPARENTED_IFRETURN_DISABLED_REASON);
Events.setGroup(group);
try {
// There is no need to record the enable/disable change on the undo/redo
// list since the change will be automatically recreated when replayed.
eventUtils.setRecordUndo(false);
this.setDisabledReason(!legal, UNPARENTED_IFRETURN_DISABLED_REASON);
} finally {
eventUtils.setRecordUndo(true);
}
}
},
/**
Expand Down

0 comments on commit 955fbe7

Please sign in to comment.