Kaydet (Commit) fe444d1f authored tarafından Michael Stahl's avatar Michael Stahl

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 062eaeff did not
 introduce the problem but made it far more annoying)

Change-Id: I58ece7f5bd5a786b22a066e5902f1784dafa5dce
üst 6db39dbd
......@@ -762,24 +762,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;
......
......@@ -188,6 +188,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.
......
......@@ -2475,7 +2475,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 );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment