From kde-commits Sat Jan 12 12:42:57 2013 From: Pierre Stirnweiss Date: Sat, 12 Jan 2013 12:42:57 +0000 To: kde-commits Subject: [calligra] libs/kotext: Fix applying style to a caret without selection. Message-Id: <20130112124257.C00C8A6091 () git ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=135799458710204 Git commit bb199de88d8b27ca1062becc20dd0e34d8c3fcba by Pierre Stirnweiss. Committed on 05/01/2013 at 08:42. Pushed by pstirnweiss into branch 'master'. Fix applying style to a caret without selection. When applying style to a caret without a selection, the previous character style properties, which are not set by the style being applied, were kept. We now reset the caret's format to the frame's text properties, apply the paragraph style's properties, and eventually the character style (if we set one). REVIEW =3D 108191 M +14 -3 libs/kotext/KoTextEditor_format.cpp http://commits.kde.org/calligra/bb199de88d8b27ca1062becc20dd0e34d8c3fcba diff --git a/libs/kotext/KoTextEditor_format.cpp b/libs/kotext/KoTextEditor= _format.cpp index 125be99..5a35fe8 100644 --- a/libs/kotext/KoTextEditor_format.cpp +++ b/libs/kotext/KoTextEditor_format.cpp @@ -447,10 +447,18 @@ void KoTextEditor::setStyle(KoCharacterStyle *style) = recursivelyVisitSelection(d->document->rootFrame()->begin(), visitor); = - if (!isEditProtected() && caretAnchor =3D=3D caretPosition) { + 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. + //applying a style is absolute, so first initialise the caret wit= h the frame's style, then apply the paragraph's. Finally apply the characte= r style + QTextCharFormat charFormat =3D KoTextDocument(d->document).frameCh= arFormat(); + KoStyleManager *styleManager =3D KoTextDocument(d->document).style= Manager(); + KoParagraphStyle *paragraphStyle =3D styleManager->paragraphStyle(= d->caret.charFormat().intProperty(KoParagraphStyle::StyleId)); + if (paragraphStyle) { + paragraphStyle->KoCharacterStyle::applyStyle(charFormat); + } + d->caret.setCharFormat(charFormat); style->applyStyle(&(d->caret)); } - else { + else { //if the caret has a selection, the visitor has already applied= the style, reset the caret's position so it picks the proper style. d->caret.setPosition(caretAnchor); d->caret.setPosition(caretPosition, QTextCursor::KeepAnchor); } @@ -500,7 +508,10 @@ void KoTextEditor::setStyle(KoParagraphStyle *style) = recursivelyVisitSelection(d->document->rootFrame()->begin(), visitor); = - if (!isEditProtected() && caretAnchor =3D=3D caretPosition) { + 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. + //applying a style is absolute, so first initialise the caret with= the frame's style, then apply the paragraph style + QTextCharFormat charFormat =3D KoTextDocument(d->document).frameCh= arFormat(); + d->caret.setCharFormat(charFormat); style->KoCharacterStyle::applyStyle(&(d->caret)); } else {