diff --git a/scribus/tests/testStoryText.cpp b/scribus/tests/testStoryText.cpp index a6ede8bf5..b8ec351cf 100644 --- a/scribus/tests/testStoryText.cpp +++ b/scribus/tests/testStoryText.cpp @@ -14,7 +14,7 @@ void TestStoryText::initST() { StoryText story; QCOMPARE(story.length(), 0); - story.insertChars(0, "Hallo Welt"); + story.insertChars(0, QString("Hallo Welt")); QCOMPARE(story.nrOfParagraphs(), 1u); QCOMPARE(story.nrOfRuns(), 1u); } @@ -25,7 +25,7 @@ void TestStoryText::addText() story.insertChars(0, QString("Hallo Welt")); QCOMPARE(story.length(), 10); QCOMPARE(story.text(0, story.length()), QString("Hallo Welt")); - story.insertChars(5, " schöne neue"); + story.insertChars(5, QString(" schöne neue")); QCOMPARE(story.text(0, story.length()), QString("Hallo schöne neue Welt")); } @@ -127,3 +127,23 @@ void TestStoryText::removeCharStyle() QCOMPARE(story.startOfRun(2), 5 + 26 + 1); QCOMPARE(story.endOfRun(2), 11 + 26); } + +void TestStoryText::preserveCharStyleInEmptyParagraph() +{ + CharStyle charStyle; + charStyle.setFontSize(240); + + StoryText trailingParagraph; + trailingParagraph.insertChars(0, QString("Styled")); + trailingParagraph.applyCharStyle(0, trailingParagraph.length(), charStyle); + trailingParagraph.insertChars(trailingParagraph.length(), SpecialChars::PARSEP, true); + trailingParagraph.insertChars(trailingParagraph.length(), QString("Text"), true); + QCOMPARE(trailingParagraph.charStyle(trailingParagraph.length() - 1).fontSize(), 240.0); + + StoryText emptyParagraph; + emptyParagraph.insertChars(0, QString("Before") + SpecialChars::PARSEP + SpecialChars::PARSEP + QString("After")); + emptyParagraph.applyCharStyle(0, emptyParagraph.length(), charStyle); + const int emptyParagraphPosition = emptyParagraph.indexOf(SpecialChars::PARSEP, 0) + 1; + emptyParagraph.insertChars(emptyParagraphPosition, QString("Text"), true); + QCOMPARE(emptyParagraph.charStyle(emptyParagraphPosition).fontSize(), 240.0); +} diff --git a/scribus/tests/testStoryText.h b/scribus/tests/testStoryText.h index 655875237..4a2ba28e1 100644 --- a/scribus/tests/testStoryText.h +++ b/scribus/tests/testStoryText.h @@ -27,4 +27,5 @@ private slots: void removePars(); void applyCharStyle(); void removeCharStyle(); + void preserveCharStyleInEmptyParagraph(); }; diff --git a/scribus/text/storytext.cpp b/scribus/text/storytext.cpp index d8281d5e0..6fa17dac4 100644 --- a/scribus/text/storytext.cpp +++ b/scribus/text/storytext.cpp @@ -689,6 +689,14 @@ void StoryText::insertChars(const QString& txt, bool applyNeighbourStyle) //, co insertChars(d->cursorPosition, txt, applyNeighbourStyle); } +const CharStyle& StoryText::charStyleForInsertion(int pos) const +{ + int referenceChar = qMax(0, qMin(pos, length() - 1)); + if (isNotEmpty() && text(referenceChar) == SpecialChars::PARSEP) + return *item(referenceChar); + return charStyle(referenceChar); +} + void StoryText::insertChars(int pos, const QString& txt, bool applyNeighbourStyle) //, const CharStyle & charstyle) { if (pos < 0) @@ -705,8 +713,7 @@ void StoryText::insertChars(int pos, const QString& txt, bool applyNeighbourStyl ScText clone; if (applyNeighbourStyle) { - int referenceChar = qMax(0, qMin(pos, length()-1)); - clone.applyCharStyle(charStyle(referenceChar)); + clone.applyCharStyle(charStyleForInsertion(pos)); clone.setEffects(ScStyle_Default); } @@ -748,8 +755,7 @@ void StoryText::insertCharsWithSoftHyphens(int pos, const QString& txt, bool app ScText clone; if (applyNeighbourStyle) { - int referenceChar = qMax(0, qMin(pos, length() - 1)); - clone.applyCharStyle(charStyle(referenceChar)); + clone.applyCharStyle(charStyleForInsertion(pos)); clone.setEffects(ScStyle_Default); } diff --git a/scribus/text/storytext.h b/scribus/text/storytext.h index 4f2fee40d..86ef5df67 100644 --- a/scribus/text/storytext.h +++ b/scribus/text/storytext.h @@ -328,6 +328,7 @@ private: QString textWithSoftHyphens (int pos, uint len) const; void insertCharsWithSoftHyphens(int pos, const QString& txt, bool applyNeighbourStyle = false); + const CharStyle& charStyleForInsertion(int pos) const; /// mark these runs as invalid, ie. need itemize and shaping void invalidate(int firstRun, int lastRun);