vcl/qt5/QtAccessibleWidget.cxx |    4 ++++
 1 file changed, 4 insertions(+)

New commits:
commit 85c564285036f92f76c1095487c5d5e12709b1e2
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Sat Jun 18 10:54:45 2022 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sat Jun 18 12:36:24 2022 +0200

    qt a11y: Handle special value of -1 for text offset
    
    As the note in the Qt doc for
    `QAccessibleTextInterface::textAtOffset` says [1]:
    
    > An offset of -1 is used for the text length and custom implementations
    > of this function have to return the result as if the length was passed
    > in as offset.
    
    Without this, LO happened to crash quite frequently with Orca enabled
    when moving the cursor between paragraphs in a Writer doc when using the
    qt6 VCL plugin in a WIP branch including more changes to qt5/qt6 a11y.
    
    [1] https://doc.qt.io/qt-6/qaccessibletextinterface.html#textAtOffset
    
    Change-Id: I5c6ca69f8a9b2edad204bb1af740d4de17668f18
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136073
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/qt5/QtAccessibleWidget.cxx b/vcl/qt5/QtAccessibleWidget.cxx
index 0211fc045c27..3461ec1ae38c 100644
--- a/vcl/qt5/QtAccessibleWidget.cxx
+++ b/vcl/qt5/QtAccessibleWidget.cxx
@@ -1039,6 +1039,10 @@ QString QtAccessibleWidget::textAtOffset(int offset, 
QAccessible::TextBoundaryTy
     sal_Int16 nUnoBoundaryType = lcl_matchQtTextBoundaryType(boundaryType);
     assert(nUnoBoundaryType > 0);
 
+    // special value of -1 for offset means text length
+    if (offset == -1)
+        offset = xText->getCharacterCount();
+
     const TextSegment segment = xText->getTextAtIndex(offset, 
nUnoBoundaryType);
     *startOffset = segment.SegmentStart;
     *endOffset = segment.SegmentEnd;

Reply via email to