summaryrefslogtreecommitdiff
path: root/editeng
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-08-09 19:20:53 +0200
committerMiklos Vajna <vmiklos@collabora.com>2021-08-10 07:43:46 +0200
commitfc4c0747e97bb997cc37263b3e86b07dab21fe25 (patch)
treed8010884689af283e8f9892758f1e0a13e4c5ad9 /editeng
parent34574d2094650673fb2f29e342eb259494088d1c (diff)
tdf#142845 editeng: don't update selection when formatting before sd paste
Regression from commit f0c25c751cf8e166a84b289746bce6202a40391d (tdf#115783 sd: fix lost char attributes during in-table copy&paste, 2018-02-16), the problem was that the formatting before paste also created an undo action, and executing it alters the selection, which was not intended. So in case the textbox contains "world" and we paste "hello", then the undo will set the cursor at the end of "world", while the expected result is to just undo the paste and the formatting of "world". Fix the problem by not altering the selection in the undo of Outliner::SetCharAttribs(), which is only called by sd/ in the before-paste case, not anywhere else. Change-Id: Ie4a08f57d22cd1862c02987a5f86089fda8a5d9d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120220 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'editeng')
-rw-r--r--editeng/source/editeng/editeng.cxx4
-rw-r--r--editeng/source/editeng/editundo.cxx11
-rw-r--r--editeng/source/editeng/editundo.hxx3
-rw-r--r--editeng/source/editeng/impedit.hxx2
-rw-r--r--editeng/source/editeng/impedit5.cxx3
5 files changed, 18 insertions, 5 deletions
diff --git a/editeng/source/editeng/editeng.cxx b/editeng/source/editeng/editeng.cxx
index abc9f64a9b04..c9aec527b222 100644
--- a/editeng/source/editeng/editeng.cxx
+++ b/editeng/source/editeng/editeng.cxx
@@ -1768,7 +1768,9 @@ const SfxPoolItem& EditEngine::GetParaAttrib( sal_Int32 nPara, sal_uInt16 nWhich
void EditEngine::SetCharAttribs(sal_Int32 nPara, const SfxItemSet& rSet)
{
EditSelection aSel(pImpEditEngine->ConvertSelection(nPara, 0, nPara, GetTextLen(nPara)));
- pImpEditEngine->SetAttribs(aSel, rSet);
+ // This is called by sd::View::OnBeginPasteOrDrop(), updating the cursor position on undo is not
+ // wanted.
+ pImpEditEngine->SetAttribs(aSel, rSet, /*nSpecial=*/SetAttribsMode::NONE, /*bSetSelection=*/false);
pImpEditEngine->FormatAndUpdate();
}
diff --git a/editeng/source/editeng/editundo.cxx b/editeng/source/editeng/editundo.cxx
index 714dd1b682ed..892183f754af 100644
--- a/editeng/source/editeng/editundo.cxx
+++ b/editeng/source/editeng/editundo.cxx
@@ -501,6 +501,7 @@ EditUndoSetAttribs::EditUndoSetAttribs(EditEngine* pEE, const ESelection& rESel,
aESel(rESel),
aNewAttribs(rNewItems),
nSpecial(SetAttribsMode::NONE),
+ m_bSetSelection(true),
// When EditUndoSetAttribs actually is a RemoveAttribs this could be
// recognize by the empty itemset, but then it would have to be caught in
// its own place, which possible a setAttribs does with an empty itemset.
@@ -560,7 +561,10 @@ void EditUndoSetAttribs::Undo()
}
if ( bFields )
pEE->UpdateFieldsOnly();
- ImpSetSelection();
+ if (m_bSetSelection)
+ {
+ ImpSetSelection();
+ }
}
void EditUndoSetAttribs::Redo()
@@ -574,7 +578,10 @@ void EditUndoSetAttribs::Redo()
else
pEE->RemoveCharAttribs( aSel, bRemoveParaAttribs, nRemoveWhich );
- ImpSetSelection();
+ if (m_bSetSelection)
+ {
+ ImpSetSelection();
+ }
}
void EditUndoSetAttribs::AppendContentInfo(ContentAttribsInfo* pNew)
diff --git a/editeng/source/editeng/editundo.hxx b/editeng/source/editeng/editundo.hxx
index 43d2a0d3b911..f87180ba7dd7 100644
--- a/editeng/source/editeng/editundo.hxx
+++ b/editeng/source/editeng/editundo.hxx
@@ -218,6 +218,8 @@ private:
InfoArrayType aPrevAttribs;
SetAttribsMode nSpecial;
+ /// Once the attributes are set / unset, set the selection to the end of the formatted range?
+ bool m_bSetSelection;
bool bSetIsRemove;
bool bRemoveParaAttribs;
sal_uInt16 nRemoveWhich;
@@ -232,6 +234,7 @@ public:
SfxItemSet& GetNewAttribs() { return aNewAttribs; }
void SetSpecial( SetAttribsMode n ) { nSpecial = n; }
+ void SetUpdateSelection( bool bSetSelection ) { m_bSetSelection = bSetSelection; }
void SetRemoveAttribs( bool b ) { bSetIsRemove = b; }
void SetRemoveParaAttribs( bool b ) { bRemoveParaAttribs = b; }
void SetRemoveWhich( sal_uInt16 n ) { nRemoveWhich = n; }
diff --git a/editeng/source/editeng/impedit.hxx b/editeng/source/editeng/impedit.hxx
index 78b2f85f9cc7..e138fa532f32 100644
--- a/editeng/source/editeng/impedit.hxx
+++ b/editeng/source/editeng/impedit.hxx
@@ -910,7 +910,7 @@ public:
SfxItemSet GetAttribs( sal_Int32 nPara, sal_Int32 nStart, sal_Int32 nEnd, GetAttribsFlags nFlags = GetAttribsFlags::ALL ) const;
SfxItemSet GetAttribs( EditSelection aSel, EditEngineAttribs nOnlyHardAttrib = EditEngineAttribs::All );
- void SetAttribs( EditSelection aSel, const SfxItemSet& rSet, SetAttribsMode nSpecial = SetAttribsMode::NONE );
+ void SetAttribs( EditSelection aSel, const SfxItemSet& rSet, SetAttribsMode nSpecial = SetAttribsMode::NONE, bool bSetSelection = true );
void RemoveCharAttribs( EditSelection aSel, EERemoveParaAttribsMode eMode, sal_uInt16 nWhich );
void RemoveCharAttribs( sal_Int32 nPara, sal_uInt16 nWhich = 0, bool bRemoveFeatures = false );
void SetFlatMode( bool bFlat );
diff --git a/editeng/source/editeng/impedit5.cxx b/editeng/source/editeng/impedit5.cxx
index 02133496bb6b..d1846f1df880 100644
--- a/editeng/source/editeng/impedit5.cxx
+++ b/editeng/source/editeng/impedit5.cxx
@@ -483,7 +483,7 @@ SfxItemSet ImpEditEngine::GetAttribs( sal_Int32 nPara, sal_Int32 nStart, sal_Int
}
-void ImpEditEngine::SetAttribs( EditSelection aSel, const SfxItemSet& rSet, SetAttribsMode nSpecial )
+void ImpEditEngine::SetAttribs( EditSelection aSel, const SfxItemSet& rSet, SetAttribsMode nSpecial, bool bSetSelection )
{
aSel.Adjust( aEditDoc );
@@ -499,6 +499,7 @@ void ImpEditEngine::SetAttribs( EditSelection aSel, const SfxItemSet& rSet, SetA
{
std::unique_ptr<EditUndoSetAttribs> pUndo = CreateAttribUndo( aSel, rSet );
pUndo->SetSpecial( nSpecial );
+ pUndo->SetUpdateSelection(bSetSelection);
InsertUndo( std::move(pUndo) );
}