summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-09-01 06:45:37 (GMT)
committerMontel Laurent <montel@kde.org>2016-09-01 06:45:37 (GMT)
commita399dc8ae555aa17eb261cd35ff56e71d4bbea41 (patch)
treea6ab79b477e620af77024f7cbd100df09ac1fcae
parentf53d5d275cff69e24756d353896546afb98bd5c7 (diff)
Fix forceautocorrection + selection
-rw-r--r--messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.cpp4
-rw-r--r--messagecomposer/src/composer-ng/richtextcomposerng.cpp9
2 files changed, 8 insertions, 5 deletions
diff --git a/messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.cpp b/messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.cpp
index d5a3c4d..974560e 100644
--- a/messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.cpp
+++ b/messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.cpp
@@ -85,10 +85,10 @@ void RichTextComposerNgTest::shouldForceAutoCorrectionWithSelection_data()
QTest::addColumn<int>("selectionEnd");
QTest::newRow("noselection") << QStringLiteral("\nboo bla bli.\nfoo faa") << QStringLiteral("\nBoo bla bli.\nFoo faa") << 0 << 0;
QTest::newRow("noselection2") << QStringLiteral("\nboo bla bli.\nfoo faa") << QStringLiteral("\nBoo bla bli.\nFoo faa") << 1 << 1;
- QTest::newRow("fullselection") << QStringLiteral("\nboo bla bli.\nfoo faa") << QStringLiteral("\nBoo bla bli.\nFoo faa") << 0 << 22;
+ QTest::newRow("fullselection") << QStringLiteral("\nboo bla bli.\nfoo faa") << QStringLiteral("\nBoo bla bli.\nFoo faa") << 0 << 21;
QTest::newRow("selection1") << QStringLiteral("\nboo bla bli.\nfoo faa") << QStringLiteral("\nBoo bla bli.\nfoo faa") << 0 << 10;
QTest::newRow("selection2") << QStringLiteral("\nboo bla bli.\nfoo faa") << QStringLiteral("\nboo bla bli.\nfoo faa") << 5 << 10;
- QTest::newRow("twouppercase") << QStringLiteral("\nBOo bla bli.\nfoo FAa") << QStringLiteral("\nBoo bla bli.\nFoo Faa") << 0 << 22;
+ QTest::newRow("twouppercase") << QStringLiteral("\nBOo bla bli.\nfoo FAa") << QStringLiteral("\nBoo bla bli.\nFoo Faa") << 0 << 21;
}
void RichTextComposerNgTest::shouldForceAutoCorrectionWithSelection()
diff --git a/messagecomposer/src/composer-ng/richtextcomposerng.cpp b/messagecomposer/src/composer-ng/richtextcomposerng.cpp
index 9294bb3..6b231a6 100644
--- a/messagecomposer/src/composer-ng/richtextcomposerng.cpp
+++ b/messagecomposer/src/composer-ng/richtextcomposerng.cpp
@@ -377,14 +377,17 @@ void RichTextComposerNg::forceAutoCorrection(bool selectedText)
QTextCursor cur = textCursor();
cur.beginEditBlock();
if (selectedText && cur.hasSelection()) {
- cur.setPosition(cur.selectionStart());
- while(!cur.selectionEnd()) {
+ const int positionStart = qMin(cur.selectionEnd(), cur.selectionStart());
+ const int positionEnd = qMax(cur.selectionEnd(), cur.selectionStart());
+ cur.setPosition(positionStart);
+ int cursorPosition = positionStart;
+ while(cursorPosition < positionEnd) {
if(isLineQuoted(cur.block().text())) {
cur.movePosition(QTextCursor::NextBlock);
} else {
cur.movePosition(QTextCursor::NextWord);
}
- int cursorPosition = cur.position();
+ cursorPosition = cur.position();
d->autoCorrection->autocorrect(richText, *document(), cursorPosition);
}
} else {