Git commit 415bb03d54671f7e03bf24963e23f68328f9125b by Pierre Stirnweiss. Committed on 13/01/2013 at 10:42. Pushed by pstirnweiss into branch 'calligra/2.6'. Fix merge style to caret without selection The style was not properly merged to the caret if there was no selected text. REVIEW: 108379 M +21 -0 libs/kotext/KoTextEditor_format.cpp http://commits.kde.org/calligra/415bb03d54671f7e03bf24963e23f68328f9125b diff --git a/libs/kotext/KoTextEditor_format.cpp b/libs/kotext/KoTextEditor= _format.cpp index 93b0fbb..aa6b5f2 100644 --- a/libs/kotext/KoTextEditor_format.cpp +++ b/libs/kotext/KoTextEditor_format.cpp @@ -562,10 +562,20 @@ void KoTextEditor::mergeAutoStyle(QTextCharFormat del= taCharFormat) { d->updateState(KoTextEditor::Private::Custom, "Formatting"); = + int caretAnchor =3D d->caret.anchor(); + int caretPosition =3D d->caret.position(); MergeAutoCharacterStyleVisitor visitor(this, deltaCharFormat); = recursivelyVisitSelection(d->document->rootFrame()->begin(), visitor); = + if (!isEditProtected() && caretAnchor =3D=3D caretPosition) { //if the= re is no selection, it can happen that the caret does not get the proper st= yle applied (begining of a block). We need to force it. + d->caret.mergeCharFormat(deltaCharFormat); + } + else { + d->caret.setPosition(caretAnchor); + d->caret.setPosition(caretPosition, QTextCursor::KeepAnchor); + } + d->updateState(KoTextEditor::Private::NoOp); emit textFormatChanged(); } @@ -625,10 +635,21 @@ void KoTextEditor::mergeAutoStyle(QTextCharFormat del= taCharFormat, QTextBlockFor { d->updateState(KoTextEditor::Private::Custom, "Formatting"); = + int caretAnchor =3D d->caret.anchor(); + int caretPosition =3D d->caret.position(); MergeAutoParagraphStyleVisitor visitor(this, deltaCharFormat, deltaBlo= ckFormat); = recursivelyVisitSelection(d->document->rootFrame()->begin(), visitor); = + if (!isEditProtected() && caretAnchor =3D=3D caretPosition) { //if the= re is no selection, it can happen that the caret does not get the proper st= yle applied (begining of a block). We need to force it. + d->caret.mergeBlockFormat(deltaBlockFormat); + d->caret.mergeBlockCharFormat(deltaCharFormat); + } + else { + d->caret.setPosition(caretAnchor); + d->caret.setPosition(caretPosition, QTextCursor::KeepAnchor); + } + d->updateState(KoTextEditor::Private::NoOp); emit textFormatChanged(); }