editeng/source/accessibility/AccessibleEditableTextPara.cxx |   38 +++---------
 1 file changed, 10 insertions(+), 28 deletions(-)

New commits:
commit be739cff91a9ee31a8055061f97e6de802f3da3d
Author:     Michael Weghorn <[email protected]>
AuthorDate: Tue Sep 9 14:56:09 2025 +0200
Commit:     Michael Weghorn <[email protected]>
CommitDate: Tue Sep 9 18:50:47 2025 +0200

    tdf#168278 editeng a11y: Normalize selection start/end index
    
    In AccessibleEditableTextPara::GetSelection, call
    ESelection::Adjust so that the earlier position in
    the text is considered the start position and the
    position later in the text is considered the end
    position, independent of whether the selection was
    done forwards or backwards.
    
    Always using the smaller index for the start index
    and the greater index for the end index matches what
    is done for Writer and what is also seen for other
    applications as well.
    
    Example results for typing "abcd", moving the mouse to
    after the "c" and selecting two characters backwards
    (i.e. "bc" is selected, with the caret being in
    front of the "b":
    
    Writer, with either the gtk3 or qt6 VCL plugin
    and the paragraph selected in Accerciser's tree view
    of the LO a11y hierarchy gives this in the IPython
    console:
    
        In [2]: acc.queryText().getSelection(0)
        Out[2]: (1, 3)
    
    For a Calc cell in edit mode, the result would
    previously be:
    
        In [4]: acc.queryText().getSelection(0)
        Out[4]: (3, 1)
    
    , but now it matches the behavior seen with
    Writer.
    
    In a quick test with Gedit on Linux and the
    URL bar on Firefox on Windows and querying
    the selection using the IAccessibleText
    selection, the lower index was always reported
    for the start index as well and the greater one
    for the end index as well.
    
    For gtk3, this additionally ensures that a selection
    count of 1 is reported for a non-zero selection
    that was done backwards as well, as
    text_wrapper_get_n_selections returns 0 if the
    end index isn't larger than the start index.
    
    Change-Id: I549d85968f62cbfc2ee4d39c5a4aeba8767df14d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190716
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <[email protected]>

diff --git a/editeng/source/accessibility/AccessibleEditableTextPara.cxx 
b/editeng/source/accessibility/AccessibleEditableTextPara.cxx
index 49950e52c12b..a4e63a9f7e0f 100644
--- a/editeng/source/accessibility/AccessibleEditableTextPara.cxx
+++ b/editeng/source/accessibility/AccessibleEditableTextPara.cxx
@@ -340,38 +340,20 @@ bool AccessibleEditableTextPara::GetSelection(sal_Int32 
&nStartPos, sal_Int32 &n
     if( !GetEditViewForwarder().GetSelection( aSelection ) )
         return false;
 
-    if( aSelection.start.nPara < aSelection.end.nPara )
-    {
-        if( aSelection.start.nPara > nPara ||
-            aSelection.end.nPara < nPara )
-            return false;
+    aSelection.Adjust();
 
-        if( nPara == aSelection.start.nPara )
-            nStartPos = aSelection.start.nIndex;
-        else
-            nStartPos = 0;
+    if (aSelection.start.nPara > nPara || aSelection.end.nPara < nPara)
+        return false;
 
-        if( nPara == aSelection.end.nPara )
-            nEndPos = aSelection.end.nIndex;
-        else
-            nEndPos = GetTextLen();
-    }
+    if (nPara == aSelection.start.nPara)
+        nStartPos = aSelection.start.nIndex;
     else
-    {
-        if( aSelection.start.nPara < nPara ||
-            aSelection.end.nPara > nPara )
-            return false;
+        nStartPos = 0;
 
-        if( nPara == aSelection.start.nPara )
-            nStartPos = aSelection.start.nIndex;
-        else
-            nStartPos = GetTextLen();
-
-        if( nPara == aSelection.end.nPara )
-            nEndPos = aSelection.end.nIndex;
-        else
-            nEndPos = 0;
-    }
+    if (nPara == aSelection.end.nPara)
+        nEndPos = aSelection.end.nIndex;
+    else
+        nEndPos = GetTextLen();
 
     return true;
 }

Reply via email to