diff options
author | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2020-03-06 12:39:32 +0100 |
---|---|---|
committer | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2020-03-09 10:33:04 +0100 |
commit | 2b7e24334c9b9c69c1ebf03ed66a2143c6aec972 (patch) | |
tree | f7a278515983a356ca499c5040c83d0dfe2e8c30 | |
parent | cb5fc86005a85af06d8ad0bf1ac7aab7649c0048 (diff) |
tdf#131184 Allow comparing text ranges in table with body text
Change-Id: I191d8778d362cd28474eea6d18bfe40044887e30
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90086
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
-rw-r--r-- | sw/qa/python/testdocuments/xtextrange.odt | bin | 10716 -> 10528 bytes | |||
-rw-r--r-- | sw/qa/python/xtextrange.py | 21 | ||||
-rw-r--r-- | sw/source/core/unocore/unotext.cxx | 12 |
3 files changed, 29 insertions, 4 deletions
diff --git a/sw/qa/python/testdocuments/xtextrange.odt b/sw/qa/python/testdocuments/xtextrange.odt Binary files differindex 5881ea44a447..70c978349869 100644 --- a/sw/qa/python/testdocuments/xtextrange.odt +++ b/sw/qa/python/testdocuments/xtextrange.odt 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 68b0576b7ba7..207ff49b94dd 100644 --- a/sw/source/core/unocore/unotext.cxx +++ b/sw/source/core/unocore/unotext.cxx @@ -996,14 +996,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(); } |