fix #292269: remember last selection for alt+left/right

This change adds code to track the current tick and track on every new single selection.
If the selection is ever lost (including by pressing Esc),
then a currentCR can be constructed from this when the user resumes navigation via Alt+left/right.
This commit is contained in:
Marc Sabatella 2019-07-17 07:19:10 -06:00 committed by anatoly-os
parent a40ecce416
commit 3feb03e11f
3 changed files with 56 additions and 0 deletions

View file

@ -71,6 +71,8 @@ Selection::Selection(Score* s)
_staffStart = 0;
_staffEnd = 0;
_activeTrack = 0;
_currentTick = Fraction(-1, 1);
_currentTrack = 0;
}
//---------------------------------------------------------
@ -160,6 +162,29 @@ ChordRest* Selection::cr() const
return 0;
}
//---------------------------------------------------------
// currentCR
//---------------------------------------------------------
ChordRest* Selection::currentCR() const
{
// no selection yet - start at very beginning, not first cr
if (_currentTick == Fraction(-1, 1))
return nullptr;
Segment* s = score()->tick2rightSegment(_currentTick);
if (!s)
return nullptr;
int track = _currentTrack;
// staff may have been removed - start at top
if (track < 0 || track >= score()->ntracks())
track = 0;
Element* e = s->element(track);
if (e && e->isChordRest())
return toChordRest(e);
else
return nullptr;
}
//---------------------------------------------------------
// activeCR
//---------------------------------------------------------
@ -647,6 +672,13 @@ void Selection::updateState()
setState(SelState::NONE);
else if (_state == SelState::NONE)
setState(SelState::LIST);
if (e) {
if (e->isSpannerSegment())
_currentTick = toSpannerSegment(e)->spanner()->tick();
else
_currentTick = e->tick();
_currentTrack = e->track();
}
if (!_score->noteEntryMode())
_score->inputState().update(e);
}

View file

@ -149,6 +149,9 @@ class Selection {
Segment* _activeSegment;
int _activeTrack;
Fraction _currentTick; // tracks the most recent selection
int _currentTrack;
QByteArray staffMimeData() const;
QByteArray symbolListMimeData() const;
SelectionFilter selectionFilter() const;
@ -202,6 +205,7 @@ class Selection {
ChordRest* activeCR() const;
bool isStartActive() const;
bool isEndActive() const;
ChordRest* currentCR() const;
Fraction tickStart() const;
Fraction tickEnd() const;
int staffStart() const { return _staffStart; }

View file

@ -2077,6 +2077,16 @@ void ScoreView::cmd(const char* s)
Element* el = score()->selection().element();
if (!el && !score()->selection().elements().isEmpty() )
el = score()->selection().elements().first();
if (!el) {
ChordRest* cr = score()->selection().currentCR();
if (cr) {
if (cr->isChord())
el = toChord(cr)->downNote();
else if (cr->isRest())
el = cr;
score()->select(el);
}
}
if (el)
cmdGotoElement(score()->nextElement());
@ -2091,6 +2101,16 @@ void ScoreView::cmd(const char* s)
Element* el = score()->selection().element();
if (!el && !score()->selection().elements().isEmpty())
el = score()->selection().elements().last();
if (!el) {
ChordRest* cr = score()->selection().currentCR();
if (cr) {
if (cr->isChord())
el = toChord(cr)->upNote();
else if (cr->isRest())
el = cr;
score()->select(el);
}
}
if (el)
cmdGotoElement(score()->prevElement());