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

Fix remove quote when we have just a "<quote>\n"

Bug found by david.
(add autotest etc.)
parent 88e17fd4
......@@ -234,4 +234,34 @@ void RichTextComposerControlerTest::shouldTextSubScript()
}
void RichTextComposerControlerTest::shouldRemoveQuote_data()
{
QTest::addColumn<QString>("input");
QTest::addColumn<QString>("output");
QTest::newRow("removequote1") << QStringLiteral(">foo\n>bla\n>blo\n") << QStringLiteral("foo\nbla\nblo\n");
QTest::newRow("withoutquote") << QStringLiteral("bli\nblo\bla\n") << QStringLiteral("bli\nblo\bla\n");
QTest::newRow("removequote2") << QStringLiteral(">foo\n>bla\n>blo") << QStringLiteral("foo\nbla\nblo");
QTest::newRow("empty") << QString() << QString();
//Bug David, new line with quote
QTest::newRow("removequotewithnewline") << QStringLiteral(">foo\n>\n>bla\n>blo\n") << QStringLiteral("foo\n\nbla\nblo\n");
}
void RichTextComposerControlerTest::shouldRemoveQuote()
{
QFETCH(QString, input);
QFETCH(QString, output);
KPIMTextEdit::RichTextComposer composer;
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);
}
QTEST_MAIN(RichTextComposerControlerTest)
......@@ -47,6 +47,8 @@ private Q_SLOTS:
void shouldTextSuperScript();
void shouldTextSubScript();
void shouldRemoveQuote_data();
void shouldRemoveQuote();
};
#endif // RICHTEXTCOMPOSERCONTROLERTEST_H
......@@ -38,6 +38,7 @@
#include <QAction>
#include <QFileInfo>
#include <QMimeData>
#include <QDebug>
using namespace KPIMTextEdit;
......@@ -468,8 +469,9 @@ int RichTextComposer::quoteLength(const QString &line) const
}
}
if (quoteFound) {
//We found a quote but it's just quote element => 1 => remove 1 char.
if (startOfText == -1) {
startOfText = line.length() - 1;
startOfText = 1;
}
return startOfText;
} else {
......
......@@ -39,6 +39,7 @@
#include <QTextDocumentFragment>
#include "textutils.h"
#include "insertimagedialog.h"
#include <QDebug>
using namespace KPIMTextEdit;
......@@ -825,8 +826,8 @@ void RichTextComposerControler::slotRemoveQuotes()
int selectionEnd = cursor.selectionEnd();
while (block.isValid() && block.position() <= selectionEnd) {
cursor.setPosition(block.position());
if (richTextComposer()->isLineQuoted(block.text())) {
int length = richTextComposer()->quoteLength(block.text());
int length = richTextComposer()->isLineQuoted(block.text());
if (length > 0) {
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, length);
cursor.removeSelectedText();
selectionEnd -= length;
......
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