Delete all and Undo duplicates the clef

• May 30, 2017 - 11:46
Reported version
3.0
Type
Functional
Severity
S3 - Major
Status
closed
Project

If I select all and delete and then undo, the clefs are being duplicated as shown below.
Steps
1. Ctr + A
2. Del
3. Ctr + Z

Before
image

After
image


Comments

Status (old) closed active
Status closed active

Yes, I can still reproduce.
OS: Windows 7 SP 1 (6.1), Arch.: x86_64, MuseScore version (32-bit): 3.0.0, revision: 08a3f1b

Status (old) active patch (code needs review)
Status active  
Type Graphical (UI) Functional

See fix #210116: Delete all and Undo duplicates the clef #3700.

Here is another way to reproduce this error.
1. Start with “My First Score”.
2. Select the clef in measure 1, and press the delete key.
(The clef is deleted, but a new clef is added before you can realize it is gone.)
3. Undo.
(The clef that was deleted in step 2 is inserted after the clef that replaced it.)

This issue is not limited to clefs. It applies to key signatures as well.
1. Start with “My First Score”.
2. Add a key signature in measure 1.
3. Select the key signature in measure 5, and press the delete key.
4. Undo.

The reason for this is simple enough. After an element is deleted, if its parent segment is empty, then the segment is deleted also, and the deletion of the segment is pushed to the undo stack. If the element happens to be a required clef or key signature, it is recreated, and a new segment is added to the measure, but the addition of the segment is not pushed to the undo stack. When this action is undone, the addition of the new segment is not undone, and the old segment is added back, resulting in duplication.

Pushing the addition of the new segment to the undo stack fixes the issue.

@ABL pointed out that this is only noticeable after a line break. If there is no explicit system break, duplicate clefs and key signatures may be created, but the parent segment is not enabled, and thus goes undetected until viewed in the debugger.