sw/qa/core/objectpositioning/data/as_char_image.docx |binary sw/qa/core/objectpositioning/objectpositioning.cxx | 23 +++++++++++++++++++ sw/source/core/text/itrcrsr.cxx | 7 ++++- 3 files changed, 28 insertions(+), 2 deletions(-)
New commits: commit 86aa18e9509e9d7537fd7b47c76ebe3379ee212f Author: Jaume Pujantell <jaume.pujant...@collabora.com> AuthorDate: Tue Nov 19 16:26:24 2024 +0100 Commit: Andras Timar <andras.ti...@collabora.com> CommitDate: Wed Nov 20 15:30:26 2024 +0100 tdf#163890 sw: fix anchor inserted shape to paragraph Since the commit 651527b4efe9700c8c8dff58ce5aa86ad5681f16 "sw: fix double-click opening frame dialog, not graphic dialog on images", when GetModelPositionForViewPoint is called on an "as-char" graphic it returns the graphic node. This makes inserted shapes anchor to page as a fallback since they don't find a text node to anchor to. With this change, the function returns the anchor text node as before if the caller explicitly asks for only text frames. Change-Id: I8cf9f0c7dcfe6f4be46435c8506e67606ce8fe9c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176775 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> (cherry picked from commit 7ee34038b12c18b34261beb303f1f945d690761c) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176855 Tested-by: Andras Timar <andras.ti...@collabora.com> Reviewed-by: Andras Timar <andras.ti...@collabora.com> diff --git a/sw/qa/core/objectpositioning/data/as_char_image.docx b/sw/qa/core/objectpositioning/data/as_char_image.docx new file mode 100644 index 000000000000..e5e02d2168e1 Binary files /dev/null and b/sw/qa/core/objectpositioning/data/as_char_image.docx differ diff --git a/sw/qa/core/objectpositioning/objectpositioning.cxx b/sw/qa/core/objectpositioning/objectpositioning.cxx index a1805bf4508e..88bac2ef4cd5 100644 --- a/sw/qa/core/objectpositioning/objectpositioning.cxx +++ b/sw/qa/core/objectpositioning/objectpositioning.cxx @@ -12,6 +12,7 @@ #include <com/sun/star/text/VertOrientation.hpp> #include <com/sun/star/drawing/XDrawPageSupplier.hpp> +#include <comphelper/propertysequence.hxx> #include <editeng/ulspitem.hxx> #include <wrtsh.hxx> @@ -452,6 +453,28 @@ CPPUNIT_TEST_FIXTURE(Test, testDoNotMirrorRtlDrawObjsLayout) // i.e. the graphic was on the left margin, not on the right margin. CPPUNIT_ASSERT_GREATER(nBodyRight, aAnchoredCenter.getX()); } + +CPPUNIT_TEST_FIXTURE(Test, testInsertShapeOnAsCharImg_tdf16890) +{ + // Given a document with an image anchored as character + createSwDoc("as_char_image.docx"); + SwDoc* pDoc = getSwDoc(); + + // Insert a shape over it + uno::Sequence<beans::PropertyValue> aArgs( + comphelper::InitPropertySequence({ { "KeyModifier", uno::Any(KEY_MOD1) } })); + dispatchCommand(mxComponent, ".uno:BasicShapes.rectangle", aArgs); + + // Check that hte new shape is anchored at para (i.e. has an anchor node) + const auto& rFrmFormats = *pDoc->GetSpzFrameFormats(); + CPPUNIT_ASSERT_EQUAL(size_t(o3tl::make_unsigned(2)), rFrmFormats.size()); + auto pShape = rFrmFormats[1]; + CPPUNIT_ASSERT(pShape); + // Without the accompanying fix in place, this test would have failed with: + // assertion failed + // - Expression: pShape->GetAnchor().GetAnchorNode() + CPPUNIT_ASSERT(pShape->GetAnchor().GetAnchorNode()); +} } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/core/text/itrcrsr.cxx b/sw/source/core/text/itrcrsr.cxx index 76bc368856fa..c5f805474f7b 100644 --- a/sw/source/core/text/itrcrsr.cxx +++ b/sw/source/core/text/itrcrsr.cxx @@ -1865,8 +1865,11 @@ TextFrameIndex SwTextCursor::GetModelPositionForViewPoint( SwPosition *pPos, con SwFrame* pLower = pTmp->GetLower(); // Allow non-text-frames to get SwGrfNode for as-char anchored images into pPos // instead of the closest SwTextNode, to be consistent with at-char behavior. - bool bChgNodeInner = pLower - && (pLower->IsTextFrame() || pLower->IsLayoutFrame() || pLower->IsNoTextFrame()); + bool bChgNodeInner + = pLower + && (pLower->IsTextFrame() || pLower->IsLayoutFrame() + || (pLower->IsNoTextFrame() + && (!pCMS || pCMS->m_eState != CursorMoveState::SetOnlyText))); Point aTmpPoint( rPoint ); if ( m_pFrame->IsRightToLeft() )