Skip to content

Commit 4056c16

Browse files
committed
Fix add multiple harmony using space merged in undo stack
If you created multiple harmonies by using the Space key to navigate between them, the creation of all these harmonies would be merged in one big undo command. This is because `endEdit` of the previous harmony would not be called until `NotationInteraction` calls `startEditText` with the next harmony, so the addition of the new harmony happend before the `endEdit` of the previous harmony. Therefore, the creation of this new harmony would be merged into the editing of the previous harmony. This is fixed by calling `endEditText` before creating the next one.
1 parent 25532f2 commit 4056c16

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

src/notation/internal/notationinteraction.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7001,7 +7001,9 @@ void NotationInteraction::navigateToNearHarmony(MoveDirection direction, bool ne
70017001
)
70027002
* ticksPerBeat);
70037003

7004-
bool needAddSegment = false;
7004+
endEditText();
7005+
7006+
startEdit(TranslatableString("undoableAction", "Navigate to next chord symbol"));
70057007

70067008
// look for next/prev beat, note, rest or chord
70077009
for (;;) {
@@ -7015,16 +7017,12 @@ void NotationInteraction::navigateToNearHarmony(MoveDirection direction, bool ne
70157017
measure = measure->nextMeasure();
70167018
if (!measure) {
70177019
LOGD("no next measure");
7020+
rollback();
70187021
return;
70197022
}
70207023
}
70217024

7022-
segment = Factory::createSegment(measure, mu::engraving::SegmentType::ChordRest, newTick - measure->tick());
7023-
if (!segment) {
7024-
LOGD("no prev segment");
7025-
return;
7026-
}
7027-
needAddSegment = true;
7025+
segment = measure->undoGetSegment(SegmentType::ChordRest, newTick);
70287026
break;
70297027
}
70307028

@@ -7041,12 +7039,6 @@ void NotationInteraction::navigateToNearHarmony(MoveDirection direction, bool ne
70417039
}
70427040
}
70437041

7044-
startEdit(TranslatableString("undoableAction", "Navigate to next chord symbol"));
7045-
7046-
if (needAddSegment) {
7047-
score()->undoAddElement(segment);
7048-
}
7049-
70507042
mu::engraving::Harmony* nextHarmony = findHarmonyInSegment(segment, track, harmony->textStyleType());
70517043
if (!nextHarmony) {
70527044
nextHarmony = createHarmony(segment, track, harmony->harmonyType());

0 commit comments

Comments
 (0)