summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-09-20 19:19:06 (GMT)
committerMontel Laurent <montel@kde.org>2016-09-20 19:19:06 (GMT)
commitd88a60e5b10f95691faece868b34c9c616173658 (patch)
tree0e6e2e5d5ee4121a44638fb172fd0a6c8e3d0f0b
parent67685ec3877c45d06ba31de9cce71eab64aef219 (diff)
Minor optimization
-rw-r--r--messagecomposer/src/composer-ng/richtextcomposerng.cpp67
1 files changed, 34 insertions, 33 deletions
diff --git a/messagecomposer/src/composer-ng/richtextcomposerng.cpp b/messagecomposer/src/composer-ng/richtextcomposerng.cpp
index 8cf8d64..4cc8e6f 100644
--- a/messagecomposer/src/composer-ng/richtextcomposerng.cpp
+++ b/messagecomposer/src/composer-ng/richtextcomposerng.cpp
@@ -370,43 +370,44 @@ QString RichTextComposerNg::toCleanHtml() const
void RichTextComposerNg::forceAutoCorrection(bool selectedText)
{
+ if (document()->isEmpty())
+ return;
if (d->autoCorrection && d->autoCorrection->isEnabledAutoCorrection()) {
- if (!document()->isEmpty()) {
- const bool richText = (textMode() == RichTextComposer::Rich);
- const int initialPosition = textCursor().position();
- QTextCursor cur = textCursor();
- cur.beginEditBlock();
- if (selectedText && cur.hasSelection()) {
- 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);
- }
- cursorPosition = cur.position();
- d->autoCorrection->autocorrect(richText, *document(), cursorPosition);
- }
- } else {
- cur.movePosition(QTextCursor::Start);
- while (!cur.atEnd()) {
- if (isLineQuoted(cur.block().text())) {
- cur.movePosition(QTextCursor::NextBlock);
- } else {
- cur.movePosition(QTextCursor::NextWord);
- }
- int cursorPosition = cur.position();
- d->autoCorrection->autocorrect(richText, *document(), cursorPosition);
+ const bool richText = (textMode() == RichTextComposer::Rich);
+ const int initialPosition = textCursor().position();
+ QTextCursor cur = textCursor();
+ cur.beginEditBlock();
+ if (selectedText && cur.hasSelection()) {
+ 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);
}
+ cursorPosition = cur.position();
+ d->autoCorrection->autocorrect(richText, *document(), cursorPosition);
}
- cur.endEditBlock();
- if (cur.position() != initialPosition) {
- cur.setPosition(initialPosition);
- setTextCursor(cur);
+ } else {
+ cur.movePosition(QTextCursor::Start);
+ while (!cur.atEnd()) {
+ if (isLineQuoted(cur.block().text())) {
+ cur.movePosition(QTextCursor::NextBlock);
+ } else {
+ cur.movePosition(QTextCursor::NextWord);
+ }
+ int cursorPosition = cur.position();
+ d->autoCorrection->autocorrect(richText, *document(), cursorPosition);
}
}
+ cur.endEditBlock();
+ if (cur.position() != initialPosition) {
+ cur.setPosition(initialPosition);
+ setTextCursor(cur);
+ }
+
}
}