mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-16 23:24:16 +00:00
a11y: Fix offset handling for AT-SPI GetCharacterAtOffset
The text retrieved using `gtk_accessible_text_get_contents` already contains only the character at the given offset, and so the character is at index 0 in `str`, rather than at the same offset again, so adjust this accordingly. With this in place, querying the character in a LibreOffice paragraph consisting of the text "Hello world." now gives the expected results with a pending LibreOffice change [1] to support the new GtkAccessibleText interface: In [1]: text = acc.queryText() In [2]: text.getCharacterAtOffset(0) Out[2]: 72 In [3]: text.getCharacterAtOffset(1) Out[3]: 101 In [4]: text.getCharacterAtOffset(2) Out[4]: 108 In [5]: text.getCharacterAtOffset(3) Out[5]: 108 In [6]: text.getCharacterAtOffset(4) Out[6]: 111 Previously, this would only work correctly for an index of 0: In [1]: text = acc.queryText() In [2]: text.getCharacterAtOffset(0) Out[2]: 72 In [3]: text.getCharacterAtOffset(1) Out[3]: 0 In [4]: text.getCharacterAtOffset(2) Out[4]: 0 In [5]: text.getCharacterAtOffset(3) Out[5]: 0 In [6]: text.getCharacterAtOffset(4) Out[6]: 0 [1] https://gerrit.libreoffice.org/c/core/+/163733
This commit is contained in:
parent
c93fa922dc
commit
ff26aa2fa7
@ -130,9 +130,8 @@ accessible_text_handle_method (GDBusConnection *connection,
|
|||||||
if (text != NULL)
|
if (text != NULL)
|
||||||
{
|
{
|
||||||
const char *str = g_bytes_get_data (text, NULL);
|
const char *str = g_bytes_get_data (text, NULL);
|
||||||
|
if (g_utf8_strlen (str, -1) > 0)
|
||||||
if (0 <= offset && offset < g_utf8_strlen (str, -1))
|
ch = g_utf8_get_char (str);
|
||||||
ch = g_utf8_get_char (g_utf8_offset_to_pointer (str, offset));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(i)", ch));
|
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(i)", ch));
|
||||||
|
Loading…
Reference in New Issue
Block a user