Skip to content

Commit

Permalink
code review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
asattely committed Jul 5, 2023
1 parent d8bdda7 commit c7c90e0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
24 changes: 24 additions & 0 deletions src/engraving/libmscore/lyrics.cpp
Expand Up @@ -313,13 +313,37 @@ bool Lyrics::isEditAllowed(EditData& ed) const
return TextBase::isEditAllowed(ed);
}

void Lyrics::adjustPrevious()
{
Lyrics* prev = prevLyrics(toLyrics(this));
if (prev) {
// search for lyric spanners to split at this point if necessary
if (prev->tick() + prev->ticks() >= tick()) {
// the previous lyric has a spanner attached that goes through this one
// we need to shorten it
Segment* s = score()->tick2segment(tick());
if (s) {
s = s->prev1(SegmentType::ChordRest);
if (s->tick() > prev->tick()) {
prev->undoChangeProperty(Pid::LYRIC_TICKS, s->tick() - prev->tick());
} else {
prev->undoChangeProperty(Pid::LYRIC_TICKS, Fraction::fromTicks(1));
}
}
}
prev->setRemoveInvalidSegments();
prev->triggerLayout();
}
}

//---------------------------------------------------------
// endEdit
//---------------------------------------------------------

void Lyrics::endEdit(EditData& ed)
{
TextBase::endEdit(ed);

triggerLayoutAll();
}

Expand Down
1 change: 1 addition & 0 deletions src/engraving/libmscore/lyrics.h
Expand Up @@ -88,6 +88,7 @@ class Lyrics final : public TextBase
Fraction endTick() const;
void removeFromScore();
void setRemoveInvalidSegments() { _removeInvalidSegments = true; }
void adjustPrevious();

using EngravingObject::undoChangeProperty;
void paste(EditData& ed, const String& txt) override;
Expand Down
21 changes: 3 additions & 18 deletions src/engraving/libmscore/textedit.cpp
Expand Up @@ -223,24 +223,9 @@ void TextBase::endEdit(EditData& ed)
triggerLayout();
}
if (isLyrics()) {
Lyrics* prev = prevLyrics(toLyrics(this));
if (prev) {
if (prev->tick() + prev->ticks() >= tick()) {
// the previous lyric has a spanner attached that goes through this one
// we need to shorten it
Segment* s = score()->tick2segment(tick());
if (s) {
s = s->prev1(SegmentType::ChordRest);
if (s->tick() > prev->tick()) {
prev->undoChangeProperty(Pid::LYRIC_TICKS, s->tick() - prev->tick());
} else {
prev->undoChangeProperty(Pid::LYRIC_TICKS, Fraction::fromTicks(1));
}
}
}
prev->setRemoveInvalidSegments();
prev->triggerLayout();
}
// we must adjust previous lyrics before the call to commitText(), in order to make the adjustments
// part of the same undo command. there is logic above that will skip this call if the text is empty
toLyrics(this)->adjustPrevious();
}

static const double w = 2.0;
Expand Down

0 comments on commit c7c90e0

Please sign in to comment.