sw/qa/extras/unowriter/data/image-comment-at-char.odt |binary sw/qa/extras/unowriter/unowriter.cxx | 16 ++++++++++++++++ sw/source/core/unocore/unofield.cxx | 6 +++--- 3 files changed, 19 insertions(+), 3 deletions(-)
New commits: commit 34c008380b9c17a78b9fde8cfa2102ab14c2392b Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Thu Jun 20 16:58:06 2019 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu Jun 20 20:46:56 2019 +0200 sw comments: allow ranges to be created which cover only the placeholder char First, the old condition was a bit tricky: it wanted to avoid the case when only the placeholder character is covered, but given that start and end can be the same for collapsed ranges, this was true for comments without a range, too. In practice what remains blacklisted is just the case when the PaM has a mark, but it's the same as the point. The change has two motivations: 1) ODF can have '<office:annotation/>...<office:annotation-end/>', where '...' may be content which has no document position itself in the Writer implementation, like at-char anchored images. This change avoids loosing the range of such annotations during ODF roundtrip. 2) This starts adding support for comments on objects which don't have an own document position, though UI for that is still missing. Change-Id: If151b8e00e37e07830c0582b8f0920a91a787363 Reviewed-on: https://gerrit.libreoffice.org/74459 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/sw/qa/extras/unowriter/data/image-comment-at-char.odt b/sw/qa/extras/unowriter/data/image-comment-at-char.odt new file mode 100644 index 000000000000..ba959d68ace9 Binary files /dev/null and b/sw/qa/extras/unowriter/data/image-comment-at-char.odt differ diff --git a/sw/qa/extras/unowriter/unowriter.cxx b/sw/qa/extras/unowriter/unowriter.cxx index 4c5d6c417949..2969b5447675 100644 --- a/sw/qa/extras/unowriter/unowriter.cxx +++ b/sw/qa/extras/unowriter/unowriter.cxx @@ -533,6 +533,22 @@ CPPUNIT_TEST_FIXTURE(SwUnoWriter, testPasteListener) CPPUNIT_ASSERT(pListener->GetString().isEmpty()); } +CPPUNIT_TEST_FIXTURE(SwUnoWriter, testImageCommentAtChar) +{ + // Load a document with an at-char image in it (and a comment on the image). + load(mpTestDocumentPath, "image-comment-at-char.odt"); + SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc(); + + // Verify that we have an annotation mark (comment with a text range) in the document. + // Without the accompanying fix in place, this test would have failed, as comments lost their + // ranges on load when their range only covered the placeholder character of the comment (which + // is also the anchor position of the image). + IDocumentMarkAccess* pMarks = pDoc->getIDocumentMarkAccess(); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), pMarks->getAnnotationMarksCount()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/unocore/unofield.cxx b/sw/source/core/unocore/unofield.cxx index 7b6cd62b4801..3c31a1124efd 100644 --- a/sw/source/core/unocore/unofield.cxx +++ b/sw/source/core/unocore/unofield.cxx @@ -2046,9 +2046,9 @@ void SAL_CALL SwXTextField::attach( if ( !::sw::XTextRangeToSwPaM( aIntPam, xTextRange ) ) throw lang::IllegalArgumentException(); - // nothing to do, if the text range only covers the former annotation field - if ( aIntPam.Start()->nNode != aIntPam.End()->nNode - || aIntPam.Start()->nContent.GetIndex() != aIntPam.End()->nContent.GetIndex()-1 ) + // Nothing to do, if the text range has a separate start and end, but they have the same + // value. + if (!aIntPam.HasMark() || *aIntPam.Start() != *aIntPam.End()) { UnoActionContext aCont( m_pImpl->m_pDoc ); // insert copy of annotation at new text range _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits