summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>2020-03-06 12:39:32 +0100
committerMichael Stahl <michael.stahl@cib.de>2020-03-11 16:40:31 +0100
commita2644485cee8b0e93751a2ca8911a411b07cd03f (patch)
tree8f16a9cfc603577e630c158be613d08dedbc2fd8
parent156f14c6632df104186feeba250abdf7de4a2e30 (diff)
tdf#131184 Allow comparing text ranges in table with body text
Change-Id: I191d8778d362cd28474eea6d18bfe40044887e30 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90038 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@cib.de>
-rw-r--r--sw/qa/python/testdocuments/xtextrange.odtbin10716 -> 10528 bytes
-rw-r--r--sw/qa/python/xtextrange.py21
-rw-r--r--sw/source/core/unocore/unotext.cxx12
3 files changed, 29 insertions, 4 deletions
diff --git a/sw/qa/python/testdocuments/xtextrange.odt b/sw/qa/python/testdocuments/xtextrange.odt
index 5881ea44a447..70c978349869 100644
--- a/sw/qa/python/testdocuments/xtextrange.odt
+++ b/sw/qa/python/testdocuments/xtextrange.odt
Binary files differ
diff --git a/sw/qa/python/xtextrange.py b/sw/qa/python/xtextrange.py
index 9c00ebad51b3..75e4aed79561 100644
--- a/sw/qa/python/xtextrange.py
+++ b/sw/qa/python/xtextrange.py
@@ -91,6 +91,27 @@ class TestXTextRange(unittest.TestCase):
xTextRange2 = xTextTable.getCellByName("A1")
self.assertEqual(xTextRange2.getString(), "beforeC1after")
+ def test_textRangesCompare(self):
+ doc = self._uno.getDoc()
+ # Bookmark in body text
+ bookmark1 = doc.getBookmarks().getByIndex(0).getAnchor()
+
+ # Bookmarks in table
+ bookmark2 = doc.getBookmarks().getByIndex(1).getAnchor()
+ bookmark3 = doc.getBookmarks().getByIndex(2).getAnchor()
+
+ res = doc.Text.compareRegionStarts(bookmark1, bookmark2)
+ self.assertEqual(res, 1)
+
+ res = doc.Text.compareRegionStarts(bookmark2, bookmark1)
+ self.assertEqual(res, -1)
+
+ res = doc.Text.compareRegionStarts(bookmark2, bookmark3)
+ self.assertEqual(res, 1)
+
+ res = doc.Text.compareRegionStarts(bookmark1, bookmark3)
+ self.assertEqual(res, 1)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sw/source/core/unocore/unotext.cxx b/sw/source/core/unocore/unotext.cxx
index db748899c582..8bdc6d575e73 100644
--- a/sw/source/core/unocore/unotext.cxx
+++ b/sw/source/core/unocore/unotext.cxx
@@ -1001,14 +1001,18 @@ bool SwXText::Impl::CheckForOwnMember(
const SwNode& rSrcNode = rPaM.GetNode();
const SwStartNode* pTmp = rSrcNode.FindSttNodeByType(eSearchNodeType);
- // skip SectionNodes
- while(pTmp && pTmp->IsSectionNode())
+ // skip SectionNodes / TableNodes to be able to compare across table/section boundaries
+ while (pTmp
+ && (pTmp->IsSectionNode() || pTmp->IsTableNode()
+ || (m_eType != CursorType::TableText
+ && pTmp->GetStartNodeType() == SwTableBoxStartNode)))
{
pTmp = pTmp->StartOfSectionNode();
}
- //if the document starts with a section
- while(pOwnStartNode->IsSectionNode())
+ while (pOwnStartNode->IsSectionNode() || pOwnStartNode->IsTableNode()
+ || (m_eType != CursorType::TableText
+ && pOwnStartNode->GetStartNodeType() == SwTableBoxStartNode))
{
pOwnStartNode = pOwnStartNode->StartOfSectionNode();
}