Skip to content

Commit a96b72c

Browse files
committed
fix #298061: fix a crash on "set as style" if score ends with a frame
- Don't pass staff number to adjustCanvasPosition if trying to adjust viewport to a frame. This avoids a crash itself. - Implement a more robust approach to determine a measure relevant to the current edit operation in CmdState. This avoids trying to unnecessarily jump to the frame at the end of a score.
1 parent 541d86d commit a96b72c

File tree

3 files changed

+40
-17
lines changed

3 files changed

+40
-17
lines changed

libmscore/cmd.cpp

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ void CmdState::reset()
9292
_endStaff = -1;
9393
_el = nullptr;
9494
_oneElement = true;
95-
_elIsMeasureBase = false;
95+
_mb = nullptr;
96+
_oneMeasureBase = true;
9697
_locked = false;
9798
}
9899

@@ -128,6 +129,19 @@ void CmdState::setStaff(int st)
128129
_endStaff = st;
129130
}
130131

132+
//---------------------------------------------------------
133+
// setMeasureBase
134+
//---------------------------------------------------------
135+
136+
void CmdState::setMeasureBase(const MeasureBase* mb)
137+
{
138+
if (!mb || _mb == mb || _locked)
139+
return;
140+
141+
_oneMeasureBase = !_mb;
142+
_mb = mb;
143+
}
144+
131145
//---------------------------------------------------------
132146
// setElement
133147
//---------------------------------------------------------
@@ -137,20 +151,11 @@ void CmdState::setElement(const Element* e)
137151
if (!e || _el == e || _locked)
138152
return;
139153

140-
// prefer measures and frames as edit targets
141-
const bool oldIsMeasureBase = _elIsMeasureBase;
142-
const bool newIsMeasureBase = e->isMeasureBase();
143-
if (newIsMeasureBase && !oldIsMeasureBase) {
144-
_oneElement = true;
145-
return;
146-
}
147-
else if (oldIsMeasureBase && !newIsMeasureBase)
148-
return; // don't remember the new element
149-
else
150-
_oneElement = !_el;
151-
154+
_oneElement = !_el;
152155
_el = e;
153-
_elIsMeasureBase = newIsMeasureBase;
156+
157+
if (_oneMeasureBase)
158+
setMeasureBase(e->findMeasureBase());
154159
}
155160

156161
//---------------------------------------------------------
@@ -161,6 +166,21 @@ void CmdState::unsetElement(const Element* e)
161166
{
162167
if (_el == e)
163168
_el = nullptr;
169+
if (_mb == e)
170+
_mb = nullptr;
171+
}
172+
173+
//---------------------------------------------------------
174+
// element
175+
//---------------------------------------------------------
176+
177+
const Element* CmdState::element() const
178+
{
179+
if (_oneElement)
180+
return _el;
181+
if (_oneMeasureBase)
182+
return _mb;
183+
return nullptr;
164184
}
165185

166186
//---------------------------------------------------------

libmscore/score.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,14 @@ class CmdState {
260260
int _startStaff = -1;
261261
int _endStaff = -1;
262262
const Element* _el = nullptr;
263+
const MeasureBase* _mb = nullptr;
263264
bool _oneElement = true;
264-
bool _elIsMeasureBase = false;
265+
bool _oneMeasureBase = true;
265266

266267
bool _locked = false;
267268

269+
void setMeasureBase(const MeasureBase* mb);
270+
268271
public:
269272
LayoutFlags layoutFlags;
270273

@@ -286,7 +289,7 @@ class CmdState {
286289
Fraction endTick() const { return _endTick; }
287290
int startStaff() const { return _startStaff; }
288291
int endStaff() const { return _endStaff; }
289-
const Element* element() const { return _oneElement ? _el : nullptr; }
292+
const Element* element() const;
290293

291294
void lock() { _locked = true; }
292295
void unlock() { _locked = false; }

mscore/scoreview.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4926,7 +4926,7 @@ void ScoreView::moveViewportToLastEdit()
49264926

49274927
const Element* viewportElement = (editElement && editElement->bbox().isValid() && !mb->isMeasure()) ? editElement : mb;
49284928

4929-
const int staff = sc->isMaster() ? st.startStaff() : -1; // TODO: choose the closest staff to the current viewport?
4929+
const int staff = sc->isMaster() && mb->isMeasure() ? st.startStaff() : -1; // TODO: choose the closest staff to the current viewport?
49304930
adjustCanvasPosition(viewportElement, /* playback */ false, staff);
49314931
}
49324932
}

0 commit comments

Comments
 (0)