summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-08-28 08:54:25 (GMT)
committerMontel Laurent <montel@kde.org>2016-08-28 08:54:25 (GMT)
commitf1ae45fd034765df019081a9d54dfaed35155a26 (patch)
tree722851b2eda888d727c2ae2706eeddd3011980be
parent5daaca99fc12cecf4c7976577817bbc8b4b395f0 (diff)
Add test for selection text
-rw-r--r--messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.cpp28
-rw-r--r--messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.h3
-rw-r--r--messagecomposer/src/composer-ng/richtextcomposerng.cpp14
3 files changed, 42 insertions, 3 deletions
diff --git a/messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.cpp b/messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.cpp
index 3e0ab6f..4795691 100644
--- a/messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.cpp
+++ b/messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.cpp
@@ -71,4 +71,32 @@ void RichTextComposerNgTest::shouldForceAutoCorrection()
QCOMPARE(richtextComposerNg.toPlainText(), expected);
}
+void RichTextComposerNgTest::shouldForceAutoCorrectionWithSelection_data()
+{
+ QTest::addColumn<QString>("original");
+ QTest::addColumn<QString>("expected");
+ QTest::addColumn<int>("selectionStart");
+ QTest::addColumn<int>("selectionEnd");
+ QTest::newRow("noselection") << QStringLiteral("\nboo bla bli.\nfoo faa") << QStringLiteral("\nBoo bla bli.\nFoo faa") << 0 << 0;
+}
+
+void RichTextComposerNgTest::shouldForceAutoCorrectionWithSelection()
+{
+ QFETCH(QString, original);
+ QFETCH(QString, expected);
+ QFETCH(int, selectionStart);
+ QFETCH(int, selectionEnd);
+
+ MessageComposer::RichTextComposerNg richtextComposerNg;
+
+ richtextComposerNg.setPlainText(original);
+ PimCommon::AutoCorrection autocorrection;
+ autocorrection.setEnabledAutoCorrection(true);
+ autocorrection.setUppercaseFirstCharOfSentence(true);
+ richtextComposerNg.setAutocorrection(&autocorrection);
+ richtextComposerNg.forceAutoCorrection(true);
+
+ QCOMPARE(richtextComposerNg.toPlainText(), expected);
+}
+
QTEST_MAIN(RichTextComposerNgTest)
diff --git a/messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.h b/messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.h
index 8b66436..b945b64 100644
--- a/messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.h
+++ b/messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.h
@@ -33,6 +33,9 @@ private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldForceAutoCorrection_data();
void shouldForceAutoCorrection();
+
+ void shouldForceAutoCorrectionWithSelection_data();
+ void shouldForceAutoCorrectionWithSelection();
};
#endif // RICHTEXTCOMPOSERNGTEST_H
diff --git a/messagecomposer/src/composer-ng/richtextcomposerng.cpp b/messagecomposer/src/composer-ng/richtextcomposerng.cpp
index 0169e46..3376726 100644
--- a/messagecomposer/src/composer-ng/richtextcomposerng.cpp
+++ b/messagecomposer/src/composer-ng/richtextcomposerng.cpp
@@ -376,9 +376,17 @@ void RichTextComposerNg::forceAutoCorrection(bool selectedText)
const int initialPosition = textCursor().position();
QTextCursor cur = textCursor();
cur.beginEditBlock();
- if (/*selectedText && cur.hasSelection()*/0) {
- //TODO
- cur.movePosition(QTextCursor::Start);
+ if (selectedText && cur.hasSelection()) {
+ cur.setPosition(cur.selectionStart());
+ while(!cur.selectionEnd()) {
+ if(isLineQuoted(cur.block().text())) {
+ cur.movePosition(QTextCursor::NextBlock);
+ } else {
+ cur.movePosition(QTextCursor::NextWord);
+ }
+ int cursorPosition = cur.position();
+ d->autoCorrection->autocorrect(richText, *document(), cursorPosition);
+ }
} else {
cur.movePosition(QTextCursor::Start);
while(!cur.atEnd()) {