Skip to content

Commit

Permalink
Fix regroup rhythms not maintaining selection
Browse files Browse the repository at this point in the history
Fixes: #24955

cmdResetNoteAndRestGroupings already saved the current selection before
actually regrouping rhythms. This commit updates the method to set the
selection to the values saved in the case that the user had selected a
range before calling regroup rhythms.

Also adds test to verify that selection is maintained when regrouping
rhythms.
  • Loading branch information
AxelMatstoms committed Dec 5, 2024
1 parent e02f6f2 commit 8aec1b7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/engraving/dom/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2803,7 +2803,12 @@ void Score::cmdResetNoteAndRestGroupings()

if (noSelection) {
deselectAll();
return;
}

// Reset selection to original selection
selection().setRangeTicks(sTick, eTick, sStaff, eStaff);
selection().updateSelectedElements();
}

static void resetBeamOffSet(void*, EngravingItem* e)
Expand Down
42 changes: 42 additions & 0 deletions src/engraving/tests/rhythmicgrouping_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,45 @@ TEST_F(Engraving_RhythmicGroupingTests, groupShortenNotes)
{
group("groupShortenNotes.mscx", "groupShortenNotes-ref.mscx"); // test for regrouping rhythms when notes should be shortened
}

TEST_F(Engraving_RhythmicGroupingTests, groupMaintainSelection)
{
MasterScore* score = ScoreRW::readScore(RHYTHMICGRP_DATA_DIR + String::fromUtf8("groupSubbeats.mscx"));
ASSERT_TRUE(score);

score->cmdSelectAll();

const Selection& selection = score->selection();
Fraction sTick = selection.tickStart();
Fraction eTick = selection.tickEnd();
staff_idx_t sStaff = selection.staffStart();
staff_idx_t eStaff = selection.staffEnd();

score->cmdResetNoteAndRestGroupings();

EXPECT_EQ(sTick, score->selection().tickStart());
EXPECT_EQ(eTick, score->selection().tickEnd());
EXPECT_EQ(sStaff, score->selection().staffStart());
EXPECT_EQ(eStaff, score->selection().staffEnd());
}

TEST_F(Engraving_RhythmicGroupingTests, groupMaintainSelectionMultipleStaves)
{
MasterScore* score = ScoreRW::readScore(RHYTHMICGRP_DATA_DIR + String::fromUtf8("group8ths4-4.mscx"));
ASSERT_TRUE(score);

score->cmdSelectAll();

const Selection& selection = score->selection();
Fraction sTick = selection.tickStart();
Fraction eTick = selection.tickEnd();
staff_idx_t sStaff = selection.staffStart();
staff_idx_t eStaff = selection.staffEnd();

score->cmdResetNoteAndRestGroupings();

EXPECT_EQ(sTick, score->selection().tickStart());
EXPECT_EQ(eTick, score->selection().tickEnd());
EXPECT_EQ(sStaff, score->selection().staffStart());
EXPECT_EQ(eStaff, score->selection().staffEnd());
}

0 comments on commit 8aec1b7

Please sign in to comment.