@@ -4805,6 +4805,25 @@ bool ScoreView::fotoMode() const
4805
4805
return false ;
4806
4806
}
4807
4807
4808
+ // ---------------------------------------------------------
4809
+ // visibleElementInScore
4810
+ // ---------------------------------------------------------
4811
+
4812
+ static const Element* visibleElementInScore (const Element* orig, const Score* s)
4813
+ {
4814
+ if (!orig)
4815
+ return nullptr ;
4816
+ if (orig->score () == s && orig->bbox ().isValid ())
4817
+ return orig;
4818
+
4819
+ for (const ScoreElement* se : orig->linkList ()) {
4820
+ const Element* e = toElement (se);
4821
+ if (e->score () == s && e->bbox ().isValid ()) // bbox check to ensure the element is indeed visible
4822
+ return e;
4823
+ }
4824
+
4825
+ return nullptr ;
4826
+ }
4808
4827
4809
4828
// ---------------------------------------------------------
4810
4829
// needViewportMove
@@ -4824,7 +4843,7 @@ static bool needViewportMove(Score* cs, ScoreView* cv)
4824
4843
4825
4844
const QRectF viewport = cv->canvasViewport (); // TODO: margins for intersection check?
4826
4845
4827
- const Element* editElement = state.element ();
4846
+ const Element* editElement = visibleElementInScore ( state.element (), cs );
4828
4847
if (editElement && editElement->bbox ().isValid () && !editElement->isSpanner ())
4829
4848
return !viewport.intersects (editElement->canvasBoundingRect ());
4830
4849
@@ -4836,8 +4855,9 @@ static bool needViewportMove(Score* cs, ScoreView* cv)
4836
4855
Measure* mEnd = cs->tick2measureMM (state.endTick ());
4837
4856
mEnd = mEnd ? mEnd ->nextMeasureMM () : nullptr ;
4838
4857
4839
- const int startStaff = state.startStaff () == -1 ? 0 : state.startStaff ();
4840
- const int endStaff = state.endStaff () == -1 ? (cs->nstaves () - 1 ) : state.endStaff ();
4858
+ const bool isExcerpt = !cs->isMaster ();
4859
+ const int startStaff = (isExcerpt || state.startStaff () == -1 ) ? 0 : state.startStaff ();
4860
+ const int endStaff = (isExcerpt || state.endStaff () == -1 ) ? (cs->nstaves () - 1 ) : state.endStaff ();
4841
4861
4842
4862
for (Measure* m = mStart ; m && m != mEnd ; m = m->nextMeasureMM ()) {
4843
4863
for (int st = startStaff; st <= endStaff; ++st) {
@@ -4876,7 +4896,8 @@ void ScoreView::moveViewportToLastEdit()
4876
4896
return ;
4877
4897
4878
4898
const CmdState& state = s->cmdState ();
4879
- const Element* editElement = state.element ();
4899
+ const Element* editElement = visibleElementInScore (state.element (), s);
4900
+
4880
4901
const MeasureBase* mb = nullptr ;
4881
4902
if (editElement)
4882
4903
mb = editElement->findMeasureBase ();
@@ -4885,7 +4906,7 @@ void ScoreView::moveViewportToLastEdit()
4885
4906
4886
4907
const Element* viewportElement = (editElement && editElement->bbox ().isValid () && !mb->isMeasure ()) ? editElement : mb;
4887
4908
4888
- const int staff = state.startStaff (); // TODO: choose the closest staff to the current viewport?
4909
+ const int staff = s-> isMaster () ? state.startStaff () : - 1 ; // TODO: choose the closest staff to the current viewport?
4889
4910
adjustCanvasPosition (viewportElement, /* playback */ false , staff);
4890
4911
}
4891
4912
}
0 commit comments