officecfg/registry/schema/org/openoffice/Office/Writer.xcs | 7 +++ sw/CppunitTest_sw_unowriter.mk | 4 + sw/qa/extras/unowriter/unowriter.cxx | 14 ++++++ sw/qa/uitest/ui/frmdlg/frmdlg.py | 3 - sw/source/core/frmedt/fecopy.cxx | 27 ++++++++----- 5 files changed, 45 insertions(+), 10 deletions(-)
New commits: commit af6a642f426944f3fb7a10dbfab2784b7fc714fb Author: Michael Stahl <michael.st...@collabora.com> AuthorDate: Wed Aug 6 12:59:26 2025 +0200 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Fri Aug 8 12:25:56 2025 +0200 tdf#167833 sw: if an anchored object is pasted, don't select it Instead, leave the cursor in the text at the paste location, like (reportedly) some version of Word does. This can be configured with the new Office::Writer::Cursor::Option::SelectPastedAnchoredObject Change-Id: Id1ddeb0e17c5cd568100d5a8169d929487d16749 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189001 Reviewed-by: Michael Stahl <michael.st...@collabora.com> Tested-by: Jenkins (cherry picked from commit 6204dfeb53aefbc4de1c82a6bfc2f6903565f5c1) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189014 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/officecfg/registry/schema/org/openoffice/Office/Writer.xcs b/officecfg/registry/schema/org/openoffice/Office/Writer.xcs index fa70c5444328..0f8adc306c13 100644 --- a/officecfg/registry/schema/org/openoffice/Office/Writer.xcs +++ b/officecfg/registry/schema/org/openoffice/Office/Writer.xcs @@ -2158,6 +2158,13 @@ </info> <value>false</value> </prop> + <prop oor:name="SelectPastedAnchoredObject" oor:type="xs:boolean" oor:nillable="false"> + <info> + <desc>Specifies if pasted anchored objects will be selected; otherwise, the text cursor will remain at the location of the paste.</desc> + <label>Select pasted anchored objects</label> + </info> + <value>false</value> + </prop> </group> </group> <group oor:name="FmtAidsAutocomplete"> diff --git a/sw/CppunitTest_sw_unowriter.mk b/sw/CppunitTest_sw_unowriter.mk index 9ed2a7522ec6..6be1fb825361 100644 --- a/sw/CppunitTest_sw_unowriter.mk +++ b/sw/CppunitTest_sw_unowriter.mk @@ -65,6 +65,10 @@ $(eval $(call gb_CppunitTest_use_vcl,sw_unowriter)) $(eval $(call gb_CppunitTest_use_rdb,sw_unowriter,services)) +$(eval $(call gb_CppunitTest_use_custom_headers,sw_unowriter,\ + officecfg/registry \ +)) + $(eval $(call gb_CppunitTest_use_configuration,sw_unowriter)) $(eval $(call gb_CppunitTest_use_uiconfigs,sw_unowriter, \ diff --git a/sw/qa/extras/unowriter/unowriter.cxx b/sw/qa/extras/unowriter/unowriter.cxx index 186e613cbc9b..07431f880876 100644 --- a/sw/qa/extras/unowriter/unowriter.cxx +++ b/sw/qa/extras/unowriter/unowriter.cxx @@ -39,7 +39,10 @@ #include <com/sun/star/text/XTextTable.hpp> #include <com/sun/star/text/XPageCursor.hpp> +#include <officecfg/Office/Writer.hxx> + #include <comphelper/propertyvalue.hxx> +#include <comphelper/scopeguard.hxx> #include <tools/UnitConversion.hxx> #include <toolkit/helper/vclunohelper.hxx> #include <vcl/graphicfilter.hxx> @@ -970,6 +973,17 @@ CPPUNIT_TEST_FIXTURE(SwUnoWriter, testRenderablePagePosition) CPPUNIT_TEST_FIXTURE(SwUnoWriter, testPasteListener) { + comphelper::ScopeGuard g([]() { + std::shared_ptr<comphelper::ConfigurationChanges> pBatch( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Writer::Cursor::Option::SelectPastedAnchoredObject::set(false, pBatch); + return pBatch->commit(); + }); + std::shared_ptr<comphelper::ConfigurationChanges> pBatch( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Writer::Cursor::Option::SelectPastedAnchoredObject::set(true, pBatch); + pBatch->commit(); + createSwDoc(); // Insert initial string. diff --git a/sw/qa/uitest/ui/frmdlg/frmdlg.py b/sw/qa/uitest/ui/frmdlg/frmdlg.py index a37062c1d392..c08b662027a6 100644 --- a/sw/qa/uitest/ui/frmdlg/frmdlg.py +++ b/sw/qa/uitest/ui/frmdlg/frmdlg.py @@ -116,7 +116,8 @@ class Test(UITestCase): self.assertTrue(to_char_enabled) def test_floattable_in_shape_text(self): - with self.ui_test.load_file(get_url_for_data_file("floattable-in-shape-text.docx")) as xComponent: + with self.ui_test.set_config('/org.openoffice.Office.Writer/Cursor/Option/SelectPastedAnchoredObject', True): + with self.ui_test.load_file(get_url_for_data_file("floattable-in-shape-text.docx")) as xComponent: # Given a table in a frame, anchored in shape text (TextBox case): self.xUITest.executeCommand(".uno:SelectAll") # Insert frame around the selected table: diff --git a/sw/source/core/frmedt/fecopy.cxx b/sw/source/core/frmedt/fecopy.cxx index 4e6ee39aa20d..956efcc9b33c 100644 --- a/sw/source/core/frmedt/fecopy.cxx +++ b/sw/source/core/frmedt/fecopy.cxx @@ -20,6 +20,7 @@ #include <memory> #include <hintids.hxx> +#include <officecfg/Office/Writer.hxx> #include <vcl/graph.hxx> #include <sot/formats.hxx> #include <svx/xfillit0.hxx> @@ -801,7 +802,8 @@ namespace { return pNew; } - void lcl_SelectFlyFormat(SwFrameFormat *const pNew, SwFEShell& rSh) + void lcl_InitSelectFlyOrDrawFormat(SwFrameFormat *const pNew, + SwFEShell & rSh, bool const isSelect) { if(!pNew) return; @@ -810,21 +812,27 @@ namespace { case RES_FLYFRMFMT: { assert(dynamic_cast<SwFlyFrameFormat*>(pNew)); - const Point aPt(rSh.GetCursorDocPos()); - SwFlyFrame* pFlyFrame = static_cast<SwFlyFrameFormat*>(pNew)->GetFrame(&aPt); - if(pFlyFrame) - rSh.SelectFlyFrame(*pFlyFrame); + if (isSelect) + { + const Point aPt(rSh.GetCursorDocPos()); + SwFlyFrame* pFlyFrame = static_cast<SwFlyFrameFormat*>(pNew)->GetFrame(&aPt); + if (pFlyFrame) + rSh.SelectFlyFrame(*pFlyFrame); + } break; } case RES_DRAWFRMFMT: { - auto& rDrawView = *rSh.Imp()->GetDrawView(); assert(dynamic_cast<SwDrawFrameFormat*>(pNew)); SwDrawFrameFormat* pDrawFormat = static_cast<SwDrawFrameFormat*>(pNew); // #i52780# - drawing object has to be made visible on paste. pDrawFormat->CallSwClientNotify(sw::DrawFrameFormatHint(sw::DrawFrameFormatHintId::PREPPASTING)); - SdrObject* pObj = pDrawFormat->FindSdrObject(); - rDrawView.MarkObj(pObj, rDrawView.GetSdrPageView()); + if (isSelect) + { + auto& rDrawView = *rSh.Imp()->GetDrawView(); + SdrObject* pObj = pDrawFormat->FindSdrObject(); + rDrawView.MarkObj(pObj, rDrawView.GetSdrPageView()); + } // #i47455# - notify draw frame format // that position attributes are already set. pDrawFormat->PosAttrSet(); @@ -1063,9 +1071,10 @@ bool SwFEShell::Paste(SwDoc& rClpDoc, bool bNestedTable) lcl_PasteFlyOrDrawFormat(rPaM, pFlyFormat, *this)); } } + bool const isSelect{officecfg::Office::Writer::Cursor::Option::SelectPastedAnchoredObject::get()}; for (auto const pFlyFormat : inserted) { - lcl_SelectFlyFormat(pFlyFormat, *this); + lcl_InitSelectFlyOrDrawFormat(pFlyFormat, *this, isSelect); } } else