Commit f9762412 authored by Laurent Montel's avatar Laurent Montel 😁

Improve removequotes

parent 13d6267c
......@@ -98,17 +98,6 @@ void RichTextComposerControlerTest::shouldHaveDefaultValue()
QVERIFY(!controler.richTextComposer()->acceptRichText());
}
void RichTextComposerControlerTest::shouldAddQuote()
{
#if 0
KPIMTextEdit::RichTextComposer composer;
KActionCollection *actionCollection = new KActionCollection(&composer);
composer.createActions(actionCollection);
KPIMTextEdit::RichTextComposerControler controler(&composer);
controler.alignLeft();
#endif
}
void RichTextComposerControlerTest::shouldBoldText()
{
......@@ -245,6 +234,12 @@ void RichTextComposerControlerTest::shouldRemoveQuote_data()
//Bug David, new line with quote
QTest::newRow("removequotewithnewline") << QStringLiteral(">foo\n>\n>bla\n>blo\n") << QStringLiteral("foo\n\nbla\nblo\n");
QTest::newRow("removequote2") << QStringLiteral(">foo\n\nbla\n>blo\nbli") << QStringLiteral("foo\n\nbla\nblo\nbli");
QTest::newRow("twoquotes") << QStringLiteral(">>foo\n\nbla\n>blo\nbli") << QStringLiteral(">foo\n\nbla\nblo\nbli");
QTest::newRow("quoteintext") << QStringLiteral("foo>>\n\nbla\n>blo\nbli") << QStringLiteral("foo>>\n\nbla\nblo\nbli");
QTest::newRow("emptyline") << QStringLiteral("foo>>\n\n\nbla\n>blo\nbli") << QStringLiteral("foo>>\n\n\nbla\nblo\nbli");
}
void RichTextComposerControlerTest::shouldRemoveQuote()
......@@ -263,5 +258,66 @@ void RichTextComposerControlerTest::shouldRemoveQuote()
QCOMPARE(composer.toPlainText(), output);
}
void RichTextComposerControlerTest::shouldRemoveQuoteWithSpecificQuote_data()
{
QTest::addColumn<QString>("input");
QTest::addColumn<QString>("output");
QTest::addColumn<QString>("quote");
QTest::newRow("empty") << QString() << QString() << QString();
QTest::newRow("empty1") << QString() << QString() << QStringLiteral("QT");
QTest::newRow("removequote1") << QStringLiteral(">foo\n>bla\n>blo\n") << QStringLiteral(">foo\n>bla\n>blo\n") << QStringLiteral("QT");
QTest::newRow("removequote2") << QStringLiteral("QTfoo\nQTbla\n>blo\n") << QStringLiteral("foo\nbla\n>blo\n") << QStringLiteral("QT");
QTest::newRow("removequote3") << QStringLiteral("|foo\n|bla\n>blo\n") << QStringLiteral("foo\nbla\n>blo\n") << QStringLiteral("|");
}
void RichTextComposerControlerTest::shouldRemoveQuoteWithSpecificQuote()
{
QFETCH(QString, input);
QFETCH(QString, output);
QFETCH(QString, quote);
KPIMTextEdit::RichTextComposer composer;
composer.setQuotePrefixName(quote);
KActionCollection *actionCollection = new KActionCollection(&composer);
composer.createActions(actionCollection);
KPIMTextEdit::RichTextComposerControler controler(&composer);
composer.show();
QTest::qWaitForWindowExposed(&composer);
composer.setPlainText(input);
controler.slotRemoveQuotes();
QCOMPARE(composer.toPlainText(), output);
}
void RichTextComposerControlerTest::shouldAddQuote_data()
{
// QTest::addColumn<QString>("input");
// QTest::addColumn<QString>("output");
// QTest::addColumn<QString>("quote");
// QTest::newRow("empty") << QString() << QString() << QString();
// QTest::newRow("empty1") << QString() << QString() << QStringLiteral("QT");
// QTest::newRow("removequote1") << QStringLiteral(">foo\n>bla\n>blo\n") << QStringLiteral("QT>foo\nQT>bla\nQT>blo\n") << QStringLiteral("QT");
// QTest::newRow("removequote2") << QStringLiteral("QTfoo\nQTbla\n>blo\n") << QStringLiteral("QTQTfoo\nQTQTbla\n>QTblo\n") << QStringLiteral("QT");
// QTest::newRow("removequote3") << QStringLiteral("|foo\n|bla\n>blo\n") << QStringLiteral("||foo\n||bla\n|>blo\n") << QStringLiteral("|");
}
void RichTextComposerControlerTest::shouldAddQuote()
{
// QFETCH(QString, input);
// QFETCH(QString, output);
// QFETCH(QString, quote);
// KPIMTextEdit::RichTextComposer composer;
// composer.setQuotePrefixName(quote);
// KActionCollection *actionCollection = new KActionCollection(&composer);
// composer.createActions(actionCollection);
// KPIMTextEdit::RichTextComposerControler controler(&composer);
// composer.show();
// QTest::qWaitForWindowExposed(&composer);
// composer.setPlainText(input);
// controler.slotAddQuotes();
// QCOMPARE(composer.toPlainText(), QString(output + QChar::ParagraphSeparator));
}
QTEST_MAIN(RichTextComposerControlerTest)
......@@ -35,7 +35,6 @@ private Q_SLOTS:
void shouldAlignRight();
void shouldAlignJustify();
void shouldHaveDefaultValue();
void shouldAddQuote();
void shouldBoldText();
void shouldItalicText();
void shouldTextUnderline();
......@@ -49,6 +48,12 @@ private Q_SLOTS:
void shouldRemoveQuote_data();
void shouldRemoveQuote();
void shouldRemoveQuoteWithSpecificQuote_data();
void shouldRemoveQuoteWithSpecificQuote();
void shouldAddQuote_data();
void shouldAddQuote();
};
#endif // RICHTEXTCOMPOSERCONTROLERTEST_H
......@@ -463,6 +463,7 @@ int RichTextComposer::quoteLength(const QString &line) const
for (int i = 0; i < lineLength; ++i) {
if (line[i] == QLatin1Char('>') || line[i] == QLatin1Char('|')) {
quoteFound = true;
break;
} else if (line[i] != QLatin1Char(' ')) {
startOfText = i;
break;
......
......@@ -826,7 +826,7 @@ void RichTextComposerControler::slotRemoveQuotes()
int selectionEnd = cursor.selectionEnd();
while (block.isValid() && block.position() <= selectionEnd) {
cursor.setPosition(block.position());
int length = richTextComposer()->isLineQuoted(block.text());
int length = richTextComposer()->quoteLength(block.text());
if (length > 0) {
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, length);
cursor.removeSelectedText();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment