[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [messagelib] messagecomposer/src/composer-ng: Add test for selection text
From: Montel Laurent <montel () kde ! org>
Date: 2016-08-28 8:54:37
Message-ID: E1bdvrR-0002lv-CJ () code ! kde ! org
[Download RAW message or body]
Git commit f1ae45fd034765df019081a9d54dfaed35155a26 by Montel Laurent.
Committed on 28/08/2016 at 08:54.
Pushed by mlaurent into branch 'master'.
Add test for selection text
M +28 -0 messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.cpp
M +3 -0 messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.h
M +11 -3 messagecomposer/src/composer-ng/richtextcomposerng.cpp
http://commits.kde.org/messagelib/f1ae45fd034765df019081a9d54dfaed35155a26
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()) {
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic