From fda3727513d4b7b128fe24e9963d7ef3a8f36802 Mon Sep 17 00:00:00 2001 From: Calum Matheson Date: Tue, 26 Nov 2024 15:34:34 +0000 Subject: [PATCH] Navigation - check if a previous selection exists before restoring --- .../internal/notationactioncontroller.cpp | 25 +++++++++++++------ .../internal/notationactioncontroller.h | 2 ++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/notation/internal/notationactioncontroller.cpp b/src/notation/internal/notationactioncontroller.cpp index 44a234ac6bcf4..d622f9078902d 100644 --- a/src/notation/internal/notationactioncontroller.cpp +++ b/src/notation/internal/notationactioncontroller.cpp @@ -617,6 +617,11 @@ INotationMidiInputPtr NotationActionController::currentNotationMidiInput() const return notation->midiInput(); } +mu::engraving::Score* NotationActionController::currentNotationScore() const +{ + return currentNotationElements() ? currentNotationElements()->msScore() : nullptr; +} + INotationStylePtr NotationActionController::currentNotationStyle() const { auto notation = currentNotation(); @@ -751,7 +756,7 @@ void NotationActionController::padNote(const Pad& pad) startNoteInputIfNeed(); noteInput->padNote(pad); - if (currentNotationElements()->msScore()->inputState().usingNoteEntryMethod(engraving::NoteEntryMethod::RHYTHM)) { + if (currentNotationScore()->inputState().usingNoteEntryMethod(engraving::NoteEntryMethod::RHYTHM)) { playSelectedElement(); } } @@ -968,7 +973,9 @@ void NotationActionController::move(MoveDirection direction, bool quickly) return; } - if (interaction->selection()->isNone()) { + const bool previousSelectionExists = currentNotationScore() && currentNotationScore()->selection().currentCR(); + if (interaction->selection()->isNone() && previousSelectionExists) { + // Try to restore the previous selection... interaction->moveSelection(direction, MoveSelectionType::EngravingItem); playSelectedElement(true); return; @@ -991,6 +998,8 @@ void NotationActionController::move(MoveDirection direction, bool quickly) } interaction->moveSelection(direction, MoveSelectionType::String); return; + } else if (interaction->selection()->isNone()) { + interaction->selectFirstElement(false); } else { interaction->movePitch(direction, quickly ? PitchMode::OCTAVE : PitchMode::CHROMATIC); } @@ -1038,6 +1047,9 @@ void NotationActionController::move(MoveDirection direction, bool quickly) if (selectedElement && selectedElement->isTextBase()) { interaction->nudge(direction, quickly); } else { + if (interaction->selection()->isNone()) { + interaction->selectFirstElement(false); + } interaction->moveSelection(direction, quickly ? MoveSelectionType::Measure : MoveSelectionType::Chord); playChord = true; } @@ -1231,7 +1243,7 @@ void NotationActionController::addFret(int num) } interaction->addFret(num); - playSelectedElement(currentNotationElements()->msScore()->playChord()); + playSelectedElement(currentNotationScore()->playChord()); } void NotationActionController::insertClef(mu::engraving::ClefType type) @@ -1991,9 +2003,8 @@ void NotationActionController::playSelectedElement(bool playChord) playbackController()->playElements({ element }); - mu::engraving::Score* score = currentNotationElements()->msScore(); - score->setPlayChord(false); - score->setPlayNote(false); + currentNotationScore()->setPlayChord(false); + currentNotationScore()->setPlayNote(false); } void NotationActionController::startNoteInputIfNeed() @@ -2092,7 +2103,7 @@ bool NotationActionController::isStandardStaff() const bool NotationActionController::isTablatureStaff() const { - return isNotEditingElement() && currentNotationElements()->msScore()->inputState().staffGroup() == mu::engraving::StaffGroup::TAB; + return isNotEditingElement() && currentNotationScore()->inputState().staffGroup() == mu::engraving::StaffGroup::TAB; } bool NotationActionController::isEditingElement() const diff --git a/src/notation/internal/notationactioncontroller.h b/src/notation/internal/notationactioncontroller.h index 5b5623a993cd0..db606ca091e79 100644 --- a/src/notation/internal/notationactioncontroller.h +++ b/src/notation/internal/notationactioncontroller.h @@ -78,6 +78,8 @@ class NotationActionController : public muse::actions::Actionable, public muse:: INotationUndoStackPtr currentNotationUndoStack() const; INotationMidiInputPtr currentNotationMidiInput() const; + mu::engraving::Score* currentNotationScore() const; + void toggleNoteInput(); void toggleNoteInputMethod(NoteInputMethod method); void toggleNoteInputInsert();