[Libreoffice-commits] core.git: Branch 'libreoffice-4-3' - sw/qa sw/source

Miklos Vajna vmiklos at collabora.co.uk
Thu Nov 20 01:16:24 PST 2014


 sw/qa/extras/uiwriter/data/commented-word.odt |binary
 sw/qa/extras/uiwriter/uiwriter.cxx            |   15 +++++++++++++++
 sw/source/core/unocore/unofield.cxx           |   14 ++++++++++++++
 3 files changed, 29 insertions(+)

New commits:
commit dd28346b4f9bd116616cd4e574f74aa5745aca60
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Nov 18 09:05:12 2014 +0100

    fdo#86131 SwXTextField::getAnchor: handle postit field with annotation mark
    
    (cherry picked from commit 2608512056b706bab57e36765e15f5c00668577a)
    
    Conflicts:
    	sw/qa/extras/uiwriter/uiwriter.cxx
    
    Change-Id: I3881c4577375a2eda053f64800d0991de6f009ad
    Reviewed-on: https://gerrit.libreoffice.org/12979
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sw/qa/extras/uiwriter/data/commented-word.odt b/sw/qa/extras/uiwriter/data/commented-word.odt
new file mode 100644
index 0000000..ab423fa
Binary files /dev/null and b/sw/qa/extras/uiwriter/data/commented-word.odt differ
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 6ec70b6..53f967a 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -37,6 +37,7 @@ public:
     void testFdo75898();
     void testFdo74981();
     void testCp1000071();
+    void testCommentedWord();
 
     CPPUNIT_TEST_SUITE(SwUiWriterTest);
     CPPUNIT_TEST(testReplaceForward);
@@ -49,6 +50,7 @@ public:
     CPPUNIT_TEST(testFdo75898);
     CPPUNIT_TEST(testFdo74981);
     CPPUNIT_TEST(testCp1000071);
+    CPPUNIT_TEST(testCommentedWord);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -306,6 +308,19 @@ void SwUiWriterTest::testCp1000071()
     CPPUNIT_ASSERT_EQUAL( redlineEnd1Index, rTbl[ 1 ]->End()->nContent.GetIndex());
 }
 
+void SwUiWriterTest::testCommentedWord()
+{
+    // This word is commented. <- string in document
+    createDoc("commented-word.odt");
+
+    // Test that getAnchor() points to "word", not to an empty string.
+    uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
+    uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
+    uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
+    uno::Reference<text::XTextContent> xField(xFields->nextElement(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("word"), xField->getAnchor()->getString());
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
 CPPUNIT_PLUGIN_IMPLEMENT();
 
diff --git a/sw/source/core/unocore/unofield.cxx b/sw/source/core/unocore/unofield.cxx
index 56be0c0..f409712 100644
--- a/sw/source/core/unocore/unofield.cxx
+++ b/sw/source/core/unocore/unofield.cxx
@@ -2036,6 +2036,20 @@ SwXTextField::getAnchor() throw (uno::RuntimeException, std::exception)
     if (pPamForTxtFld.get() == NULL)
         return 0;
 
+    // If this is a postit field, then return the range of its annotation mark if it has one.
+    if (const SwPostItField* pPostItField = dynamic_cast<const SwPostItField*>(pField))
+    {
+        IDocumentMarkAccess* pMarkAccess = m_pImpl->m_pDoc->getIDocumentMarkAccess();
+        for (IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->getAnnotationMarksBegin(); ppMark != pMarkAccess->getAnnotationMarksEnd(); ++ppMark)
+        {
+            if (ppMark->get()->GetName() == pPostItField->GetName())
+            {
+                pPamForTxtFld.reset(new SwPaM(ppMark->get()->GetMarkStart(), ppMark->get()->GetMarkEnd()));
+                break;
+            }
+        }
+    }
+
     uno::Reference<text::XTextRange> xRange = SwXTextRange::CreateXTextRange(
             *m_pImpl->m_pDoc, *(pPamForTxtFld->GetPoint()), pPamForTxtFld->GetMark());
     return xRange;


More information about the Libreoffice-commits mailing list