Add a way to force undo/redo operations to be kept in MERGE_ENDS mode #53713
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The MERGE_ENDS mode is used by the inspector to merge together actions with the same name, keeping only the undo operations from the first action, and the do operations from the last one. Theoretically, this work fine with most situations, like when you are editing a simple property, however, this might cause issue when modifying a property value might impact other properties. In such case, you might want to add an undo method when you detect the problematic value change.
The problem with the current master implementation, is that adding such an undo operation in the middle of a set of merged actions is not possible. Such operation is in fact automatically dropped.
This PR solves the problem by adding two methods
start_force_keep_in_merge_ends
andend_force_keep_in_merge_ends
, to respectively start and end a block where all defined undo/do operations are marked as to be kept and processed, even in the MERGE_ENDS mode.This solution has the advantage to keep compatibility. As the use case is not very common, I think it's better to keep it that way instead of adding an argument to the
add_do_*
andadd_undo_*
methods, which would be mainly problematic with theadd_do_method
andadd_undo_method
as they have variable argument lists.This PR also solve a mistake in the documentation of the
MERGE_ENDS
constant.Here is the script I used to test my changes: