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.
See #172
In stock, undo state is captured after part events are complete, and undoing will restore the state captured before that.
This make the user experience quite poor as undoing will loose all PAW tweaks made in between attach/detach actions.
This patch invert the undo/redo state capture logic, by moving state capture before attaching / detaching instead of after, and by capturing the current state when undoing is requested, in case a redo is requested next (see the RestoreState() patch)
Unfortunately, the crew assignement (VesselCrewManifest) is updated based on the last serialized undo state, so doing this notably result in the crew assignement window being out of sync with the ship current state. To fix this, after attaching or detaching, we call a reimplementation of the VesselCrewManifest update using the live ship state instead of the serialized state.
Still, due to many mostly unrelated code paths being triggered from the undo/redo code, this patch introduce a bunch of unavoidable behavior changes. We fix the most obvious, ie GameEvents.onEditorShipModified.Fire() being called before attach/detach, but this still introduce other more subtle shared/static state changes, which might cause weird side effects in plugins.
Here are binaries with the changes :
KSPCommunityFixes_1.34.0_BetterEditorUndoRedo.zip
It would be nice to get some testing on this. Things to look for :