Skip to content

Commit

Permalink
Merge pull request #3019 from ericfont/176151-MultiByteChar
Browse files Browse the repository at this point in the history
fix #176151 MultiByte char TextBlock::remove()
  • Loading branch information
lasconic committed Feb 22, 2017
2 parents c2ef50f + 1b67e23 commit 11ac035
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 5 deletions.
9 changes: 5 additions & 4 deletions libmscore/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,15 +568,16 @@ void TextBlock::remove(int column)
int rcol = 0;
for (const QChar& c : i->text) {
if (col == column) {
if (c.isSurrogate())
i->text.remove(rcol, 2);
if (i->format.type() == CharFormatType::SYMBOL) {
i->ids.removeAt(idx);
if (i->ids.empty())
_text.erase(i);
}
else {
i->text.remove(rcol, 1);
else {
if (c.isSurrogate())
i->text.remove(idx, 2);
else
i->text.remove(idx, 1);
if (i->text.isEmpty())
_text.erase(i);
}
Expand Down
2 changes: 1 addition & 1 deletion libmscore/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class TextFragment {

public:
mutable CharFormat format;
QPointF pos; // y is relativ to TextBlock->y()
QPointF pos; // y is relative to TextBlock->y()

mutable QString text;
QList<SymId> ids;
Expand Down
83 changes: 83 additions & 0 deletions mtest/libmscore/text/tst_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class TestText : public QObject, public MTest
void testCompatibility();
void testDelete();
void testReadWrite();
void testBMPDeletePreviousChar();
void testSMPDeletePreviousChar();
void testMixedTypesDeletePreviousChar();
};

//---------------------------------------------------------
Expand Down Expand Up @@ -186,6 +189,17 @@ void TestText::testSpecialSymbols()
text->insertText("&gt;");
text->endEdit();
QCOMPARE(text->xmlText(), QString("&amp;gt;"));

text->selectAll();
text->deleteSelectedText();
text->insertText("&&");
text->moveCursorToEnd();
text->deletePreviousChar();
text->endEdit();
QCOMPARE(text->xmlText(), QString("&amp;"));
text->deletePreviousChar();
text->endEdit();
QCOMPARE(text->xmlText(), QString(""));
}

//---------------------------------------------------------
Expand Down Expand Up @@ -417,6 +431,75 @@ void TestText::testReadWrite() {
testrw(score, text);
}

//---------------------------------------------------------
/// testBMPDeletePreviousChar
/// text contains Basic Multilingual Plane unicode symobls
//---------------------------------------------------------

void TestText::testBMPDeletePreviousChar()
{
Text* text = new Text(score);
text->initSubStyle(SubStyle::DYNAMICS);

text->setPlainText(QString("⟁⟂⟃⟄"));

text->layout();
text->startEdit(0, QPoint());
text->moveCursorToEnd();
text->deletePreviousChar();
text->endEdit();

QCOMPARE(text->xmlText(), QString("⟁⟂⟃"));
}

//---------------------------------------------------------
/// testSMPDeletePreviousChar
/// text contains Supplementary Multilingual Plane unicode symbols (https://en.wikipedia.org/wiki/Plane_(Unicode)#Supplementary_Multilingual_Plane) which store chars in pairs
//---------------------------------------------------------

void TestText::testSMPDeletePreviousChar()
{
Text* text = new Text(score);
text->initSubStyle(SubStyle::DYNAMICS);

text->setPlainText(QString("𝄆𝄆𝄆𝄏𝄏𝄏"));

text->layout();
text->startEdit(0, QPoint());
text->moveCursorToEnd();
text->deletePreviousChar();
text->endEdit();

QCOMPARE(text->xmlText(), QString("𝄆𝄆𝄆𝄏𝄏"));
}

//---------------------------------------------------------
/// testMixedTypesDeletePreviousChar
/// text contains unicode symbols from both Basic and Supplementary Multilingual Plane chars and SMUFL symbols
//---------------------------------------------------------

void TestText::testMixedTypesDeletePreviousChar()
{
Text* text = new Text(score);
text->initSubStyle(SubStyle::DYNAMICS);

text->setXmlText("<sym>cClefSquare</sym>𝄆<sym>repeatLeft</sym><sym>textBlackNoteLongStem</sym><sym>textBlackNoteLongStem</sym><sym>noteheadWhole</sym> ⟂<sym>repeatRight</sym> 𝄇");
text->layout();
text->startEdit(0, QPoint());
text->moveCursorToEnd();
text->deletePreviousChar();
text->deletePreviousChar();
text->deletePreviousChar();
text->deletePreviousChar();
text->deletePreviousChar();
text->deletePreviousChar();
text->endEdit();
QCOMPARE(text->xmlText(), QString("<sym>cClefSquare</sym>𝄆<sym>repeatLeft</sym><sym>textBlackNoteLongStem</sym><sym>textBlackNoteLongStem</sym>"));
}




QTEST_MAIN(TestText)

#include "tst_text.moc"
Expand Down

0 comments on commit 11ac035

Please sign in to comment.