fix #151521: restore selection for all linked scores on undo/redo #3160
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.
Currently, we begin each undoable command with a "SaveState" - basically remembering the input state and selection, so we can restore it on undo. Howeve,r we only do this for the score actually being edited, not for any linked scores. As a result, if you perform an operation while viewing the score but undo while viewing a part (or vice versa), strange things can happen. In particular, if you had anything selected when you pressed Ctrl+Z, that may or may not still be a valid selection when the operation completes, and we have no way of detecting problems here. As result, you can get a crash if you try doing an operation on the selection after an undo of an operation originally performed in another linked score.
I see two basic ways of dealing with this. One is to do the same thing we do on every regular command: clear the selection in all linked scores (except the one we are actually editing). However, due to the way things are structured, this wasn't actually as simple as it seemed it would be at first. It turned out to be easier to do what I considered the better solution: saving/restoring state for all linked scores on every command.
Seems to work just fine; I haven't been able to break it. Since it affects pretty much all commands on scores with linked parts, though, it really should get more testing.