sw/qa/core/data/docm/testDocumentRange.docm |binary sw/qa/core/data/docm/testFind.docm |binary sw/qa/core/macros-test.cxx | 4 +++ sw/source/ui/vba/vbadocument.cxx | 30 +++++++++++++++++++--------- 4 files changed, 25 insertions(+), 9 deletions(-)
New commits: commit 4205fb723144e825ae75e977034a6df1a99f4881 Author: Hannah Meeks <hmeeks4...@gmail.com> AuthorDate: Wed Jul 20 13:33:26 2022 +0100 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Wed Jul 20 22:45:18 2022 +0200 VBA Fix off by one error in setting range xEnd should not be smaller than xStart for compatibility Add first Document tests Change-Id: Ia8898d79db8c2885c6253ee9aaca793082b9dd20 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137262 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/sw/qa/core/data/docm/testDocumentRange.docm b/sw/qa/core/data/docm/testDocumentRange.docm new file mode 100755 index 000000000000..f1d5b328c383 Binary files /dev/null and b/sw/qa/core/data/docm/testDocumentRange.docm differ diff --git a/sw/qa/core/data/docm/testFind.docm b/sw/qa/core/data/docm/testFind.docm old mode 100644 new mode 100755 index 115fb95b3259..afcba6f0e5d0 Binary files a/sw/qa/core/data/docm/testFind.docm and b/sw/qa/core/data/docm/testFind.docm differ diff --git a/sw/qa/core/macros-test.cxx b/sw/qa/core/macros-test.cxx index 147e10dda222..dd612ae509d8 100644 --- a/sw/qa/core/macros-test.cxx +++ b/sw/qa/core/macros-test.cxx @@ -109,6 +109,10 @@ void SwMacrosTest::testVba() { OUString("testFind.docm"), OUString("vnd.sun.Star.script:Project.Module1.testAll?language=Basic&location=document") + }, + { + OUString("testDocumentRange.docm"), + OUString("vnd.sun.Star.script:Project.Module1.testAll?language=Basic&location=document") } /* TODO - make these pass in Writer { diff --git a/sw/source/ui/vba/vbadocument.cxx b/sw/source/ui/vba/vbadocument.cxx index 4a1a8dd8a2ae..79faf58fe4ab 100644 --- a/sw/source/ui/vba/vbadocument.cxx +++ b/sw/source/ui/vba/vbadocument.cxx @@ -137,22 +137,34 @@ SwVbaDocument::Range( const uno::Any& rStart, const uno::Any& rEnd ) sal_Int32 nEnd = 0; rStart >>= nStart; rEnd >>= nEnd; - nStart--; - nEnd--; uno::Reference< text::XTextRange > xStart; uno::Reference< text::XTextRange > xEnd; - if( nStart != -1 || nEnd != -1 ) - { - if( nStart == -1 ) - xStart = mxTextDocument->getText()->getStart(); - else - xStart = SwVbaRangeHelper::getRangeByPosition( mxTextDocument->getText(), nStart ); - if( nEnd == -1 ) + if( nStart > nEnd) + throw uno::RuntimeException(); + + if( nEnd != 0) + { + if( nEnd == nStart ) + { + xStart = mxTextDocument->getText()->getEnd(); xEnd = mxTextDocument->getText()->getEnd(); + } else + { xEnd = SwVbaRangeHelper::getRangeByPosition( mxTextDocument->getText(), nEnd ); + + if( nStart != 0 ) + xStart = SwVbaRangeHelper::getRangeByPosition( mxTextDocument->getText(), nStart ); + else + xStart = mxTextDocument->getText()->getStart(); + } + } + else + { + xStart = mxTextDocument->getText()->getEnd(); + xEnd = mxTextDocument->getText()->getEnd(); } if( !xStart.is() && !xEnd.is() )