tdf#79717 save/restore character format on selection overwrite
Change-Id: Ic82c50d07cf4a2208a6e2956c8b9ebc4f8630b31
Reviewed-on: https://gerrit.libreoffice.org/67597
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx
index 6d9a11e..8ea0524 100644
--- a/sw/source/uibase/wrtsh/wrtsh1.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh1.cxx
@@ -41,6 +41,7 @@
#include <svtools/ehdl.hxx>
#include <svtools/soerr.hxx>
#include <unotools/moduleoptions.hxx>
#include <editeng/rsiditem.hxx>
#include <editeng/sizeitem.hxx>
#include <editeng/formatbreakitem.hxx>
#include <editeng/svxacorr.hxx>
@@ -185,6 +186,10 @@
bCallIns = m_bIns /*|| bHasSel*/;
bool bDeleted = false;
SfxItemSet aCharAttrSet(
GetAttrPool(),
svl::Items<RES_CHRATR_BEGIN, RES_CHRATR_END - 1>{});
if( bHasSel || ( !m_bIns && SelectHiddenRange() ) )
{
// Only here parenthesizing, because the normal
@@ -204,6 +209,13 @@
aRewriter.AddRule(UndoArg3, aTmpStr);
}
// tdf#79717 Save character formatting of the start of the selection
const SwPosition *pStart = GetCursor()->Start();
SwPaM aPaM(pStart->nNode.GetNode(), pStart->nContent.GetIndex(),
pStart->nNode.GetNode(), pStart->nContent.GetIndex() + 1);
aCharAttrSet.ClearItem(RES_CHRATR_RSID);
GetPaMAttr(&aPaM, aCharAttrSet);
StartUndo(SwUndoId::REPLACE, &aRewriter);
bStarted = true;
bDeleted = DelRight();
@@ -212,6 +224,22 @@
bCallIns ?
SwEditShell::Insert2( rStr, bDeleted ) : SwEditShell::Overwrite( rStr );
if( bDeleted )
{
// tdf#79717 Restore formatting of the deleted selection
SwPosition* pEnd = GetCursor()->Start();
SwPaM aPaM(pEnd->nNode.GetNode(), pEnd->nContent.GetIndex() - rStr.getLength(),
pEnd->nNode.GetNode(), pEnd->nContent.GetIndex());
std::set<sal_uInt16> aAttribs;
for (sal_uInt16 i = RES_CHRATR_BEGIN; i < RES_CHRATR_END; ++i)
if (i != sal_uInt16(RES_CHRATR_RSID))
aAttribs.insert(aAttribs.end(), i);
ResetAttr(aAttribs, &aPaM);
SetAttrSet(aCharAttrSet, SetAttrMode::DEFAULT, &aPaM);
}
if( bStarted )
{
EndAllAction();