diff --git a/libmscore/text.cpp b/libmscore/text.cpp index 42d45fbc57b4..3df522932da9 100644 --- a/libmscore/text.cpp +++ b/libmscore/text.cpp @@ -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); } diff --git a/libmscore/text.h b/libmscore/text.h index 1435b52a2610..e0a37e7618fc 100644 --- a/libmscore/text.h +++ b/libmscore/text.h @@ -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 ids; diff --git a/mtest/libmscore/text/tst_text.cpp b/mtest/libmscore/text/tst_text.cpp index 56665d96b20c..caa5b6633640 100644 --- a/mtest/libmscore/text/tst_text.cpp +++ b/mtest/libmscore/text/tst_text.cpp @@ -38,6 +38,9 @@ class TestText : public QObject, public MTest void testCompatibility(); void testDelete(); void testReadWrite(); + void testBMPDeletePreviousChar(); + void testSMPDeletePreviousChar(); + void testMixedTypesDeletePreviousChar(); }; //--------------------------------------------------------- @@ -186,6 +189,17 @@ void TestText::testSpecialSymbols() text->insertText(">"); text->endEdit(); QCOMPARE(text->xmlText(), QString(">")); + + text->selectAll(); + text->deleteSelectedText(); + text->insertText("&&"); + text->moveCursorToEnd(); + text->deletePreviousChar(); + text->endEdit(); + QCOMPARE(text->xmlText(), QString("&")); + text->deletePreviousChar(); + text->endEdit(); + QCOMPARE(text->xmlText(), QString("")); } //--------------------------------------------------------- @@ -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("cClefSquare𝄆repeatLefttextBlackNoteLongStemtextBlackNoteLongStemnoteheadWholerepeatRight 𝄇"); + 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("cClefSquare𝄆repeatLefttextBlackNoteLongStemtextBlackNoteLongStem")); + } + + + + QTEST_MAIN(TestText) #include "tst_text.moc"