editeng/source/misc/svxacorr.cxx | 13 ++++++++----- sw/inc/swtypes.hxx | 2 ++ sw/source/core/doc/docfmt.cxx | 24 ++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 5 deletions(-)
New commits: commit 5b3867f801dadc5c2c6346561e7d71990cd7eb33 Author: Michael Stahl <mst...@redhat.com> Date: Thu Jun 20 00:20:52 2013 +0200 fdo#62536: sw: fix AutoCorrect bold/underline on existing AUTOFMT With the native AUTOFMT in Writer the SETATTR_DONTEXPAND does no longer work reliably: if there is an existing AUTOFMT at the position then it will be modified and no new hint with DontExpand will be inserted. Work around this deficiency by inserting a no-length hint with the preivous formatting at the end of the range. (similar fix to the i#75891 problem in SwTextShell::InsertSymbol) (commit 062eaeffe7cb986255063bb9b0a5f3fb3fc8e34c did not introduce the problem but made it far more annoying) Change-Id: I58ece7f5bd5a786b22a066e5902f1784dafa5dce (cherry picked from commit fe444d1f74abe417962be0bcd3340f40f2446b58) Reviewed-on: https://gerrit.libreoffice.org/4393 Reviewed-by: Noel Power <noel.po...@suse.com> Tested-by: Noel Power <noel.po...@suse.com> diff --git a/editeng/source/misc/svxacorr.cxx b/editeng/source/misc/svxacorr.cxx index cf486af..046c4b3 100644 --- a/editeng/source/misc/svxacorr.cxx +++ b/editeng/source/misc/svxacorr.cxx @@ -732,24 +732,27 @@ sal_Bool SvxAutoCorrect::FnChgWeightUnderl( SvxAutoCorrDoc& rDoc, const String& if( STRING_NOTFOUND != nFndPos ) { - // Span the Attribute over the area and delete the Character found at + // first delete the Character at the end - this allows insertion + // of an empty hint in SetAttr which would be removed by Delete + // (fdo#62536, AUTOFMT in Writer) + rDoc.Delete( nEndPos, nEndPos + 1 ); + rDoc.Delete( nFndPos, nFndPos + 1 ); + // Span the Attribute over the area // the end. if( '*' == cInsChar ) // Bold { SvxWeightItem aSvxWeightItem( WEIGHT_BOLD, SID_ATTR_CHAR_WEIGHT ); - rDoc.SetAttr( nFndPos + 1, nEndPos, + rDoc.SetAttr( nFndPos, nEndPos - 1, SID_ATTR_CHAR_WEIGHT, aSvxWeightItem); } else // underline { SvxUnderlineItem aSvxUnderlineItem( UNDERLINE_SINGLE, SID_ATTR_CHAR_UNDERLINE ); - rDoc.SetAttr( nFndPos + 1, nEndPos, + rDoc.SetAttr( nFndPos, nEndPos - 1, SID_ATTR_CHAR_UNDERLINE, aSvxUnderlineItem); } - rDoc.Delete( nEndPos, nEndPos + 1 ); - rDoc.Delete( nFndPos, nFndPos + 1 ); } return STRING_NOTFOUND != nFndPos; diff --git a/sw/inc/swtypes.hxx b/sw/inc/swtypes.hxx index fe1c414..214ba5a 100644 --- a/sw/inc/swtypes.hxx +++ b/sw/inc/swtypes.hxx @@ -192,6 +192,8 @@ typedef sal_uInt16 SetAttrMode; namespace nsSetAttrMode { const SetAttrMode SETATTR_DEFAULT = 0x0000; // Default. + /// @attention: DONTEXPAND does not work very well for CHARATR + /// because it can expand only the whole AUTOFMT or nothing const SetAttrMode SETATTR_DONTEXPAND = 0x0001; // Don't expand text attribute any further. const SetAttrMode SETATTR_DONTREPLACE = 0x0002; // Don't replace another text attribute. diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx index 4341aa9..c3171cd 100644 --- a/sw/source/core/doc/docfmt.cxx +++ b/sw/source/core/doc/docfmt.cxx @@ -2453,7 +2453,31 @@ void SwDoc::SetFmtItemByAutoFmt( const SwPaM& rPam, const SfxItemSet& rSet ) SetRedlineMode_intern( (RedlineMode_t)(eOld | nsRedlineMode_t::REDLINE_IGNORE)); } + xub_StrLen const nEnd(rPam.End()->nContent.GetIndex()); + std::vector<sal_uInt16> whichIds; + SfxItemIter iter(rSet); + for (SfxPoolItem const* pItem = iter.FirstItem(); + pItem; pItem = iter.NextItem()) + { + whichIds.push_back(pItem->Which()); + whichIds.push_back(pItem->Which()); + } + whichIds.push_back(0); + SfxItemSet currentSet(GetAttrPool(), &whichIds[0]); + pTNd->GetAttr(currentSet, nEnd, nEnd, false, true, false); + for (size_t i = 0; whichIds[i]; i += 2) + { // yuk - want to explicitly set the pool defaults too :-/ + currentSet.Put(currentSet.Get(whichIds[i], true)); + } + InsertItemSet( rPam, rSet, nsSetAttrMode::SETATTR_DONTEXPAND ); + + // fdo#62536: DONTEXPAND does not work when there is already an AUTOFMT + // here, so insert the old attributes as an empty hint to stop expand + SwPaM endPam(*pTNd, nEnd); + endPam.SetMark(); + InsertItemSet(endPam, currentSet, nsSetAttrMode::SETATTR_DEFAULT); + SetRedlineMode_intern( eOld ); } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits