summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
authorColomban Wendling <cwendling@hypra.fr>2023-05-02 20:50:52 +0200
committerMichael Weghorn <m.weghorn@posteo.de>2023-05-23 18:39:08 +0200
commitbd5c3582581f37513f45b518e348f443d5d57334 (patch)
tree6e9bce540afb614154d695b6e3280a198254b089 /comphelper
parentdce8d2dbc48eb1c7597afec236dc51b4b8aede9c (diff)
a11y: Fix returning unpaired surrogates when retrieving characters
Fix implementations of XAccessibleText's getTextAtIndex(), getTextBeforeIndex() and getTextBehindIndex() when called with AccessibleTextType::CHARACTER to return the whole code point rather than an unpaired surrogate. This is still not perfect because XAccessibleText::getCharacterCount() will return an incorrect value (code units rather than code points), but it fixes the most useful case of retrieving the character at e.g. the caret offset. This fixes the GTK3 and Windows backends as well without further changes. Qt6 also mostly works according to Michael Weghorn, but for a bug on Qt's side (https://bugreports.qt.io/browse/QTBUG-113438). MacOS backend doesn't seem to be affected in the first place. Change-Id: I53f07bcba78c6b267939257542a521b106101e96 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151303 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/source/misc/accessibletexthelper.cxx25
1 files changed, 17 insertions, 8 deletions
diff --git a/comphelper/source/misc/accessibletexthelper.cxx b/comphelper/source/misc/accessibletexthelper.cxx
index da39ac1ce252..06752ba88ded 100644
--- a/comphelper/source/misc/accessibletexthelper.cxx
+++ b/comphelper/source/misc/accessibletexthelper.cxx
@@ -297,9 +297,12 @@ namespace comphelper
{
if ( implIsValidIndex( nIndex, nLength ) )
{
- aResult.SegmentText = sText.copy( nIndex, 1 );
+ auto nIndexEnd = nIndex;
+ sText.iterateCodePoints(&nIndexEnd);
+
+ aResult.SegmentText = sText.copy( nIndex, nIndexEnd - nIndex );
aResult.SegmentStart = nIndex;
- aResult.SegmentEnd = nIndex+1;
+ aResult.SegmentEnd = nIndexEnd;
}
}
break;
@@ -401,9 +404,12 @@ namespace comphelper
{
if ( implIsValidIndex( nIndex - 1, nLength ) )
{
- aResult.SegmentText = sText.copy( nIndex - 1, 1 );
- aResult.SegmentStart = nIndex-1;
- aResult.SegmentEnd = nIndex;
+ sText.iterateCodePoints(&nIndex, -1);
+ auto nIndexEnd = nIndex;
+ sText.iterateCodePoints(&nIndexEnd);
+ aResult.SegmentText = sText.copy(nIndex, nIndexEnd - nIndex);
+ aResult.SegmentStart = nIndex;
+ aResult.SegmentEnd = nIndexEnd;
}
}
break;
@@ -525,9 +531,12 @@ namespace comphelper
{
if ( implIsValidIndex( nIndex + 1, nLength ) )
{
- aResult.SegmentText = sText.copy( nIndex + 1, 1 );
- aResult.SegmentStart = nIndex+1;
- aResult.SegmentEnd = nIndex+2;
+ sText.iterateCodePoints(&nIndex);
+ auto nIndexEnd = nIndex;
+ sText.iterateCodePoints(&nIndexEnd);
+ aResult.SegmentText = sText.copy(nIndex, nIndexEnd - nIndex);
+ aResult.SegmentStart = nIndex;
+ aResult.SegmentEnd = nIndexEnd;
}
}
break;