From 3c217d29023668abdefe288e015964a3e068117c Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Tue, 5 Mar 2024 16:00:49 +0100 Subject: [PATCH] cally: Use text length if caret is at the end of ClutterText ClutterText uses -1 to express the caret being at the end of the text content. A11y expects this position to be equivalent to the number of characters in the text, fetch that if the position is at the end. Closes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/7459 Part-of: --- clutter/clutter/cally/cally-text.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/clutter/clutter/cally/cally-text.c b/clutter/clutter/cally/cally-text.c index 1083caf32..625d0a17f 100644 --- a/clutter/clutter/cally/cally-text.c +++ b/clutter/clutter/cally/cally-text.c @@ -1180,13 +1180,21 @@ cally_text_get_text_after_offset (AtkText *text, static gint cally_text_get_caret_offset (AtkText *text) { - ClutterActor *actor = NULL; + ClutterActor *actor = NULL; + ClutterTextBuffer *buffer; + int cursor_pos; actor = CALLY_GET_CLUTTER_ACTOR (text); if (actor == NULL) /* State is defunct */ return -1; - return clutter_text_get_cursor_position (CLUTTER_TEXT (actor)); + cursor_pos = clutter_text_get_cursor_position (CLUTTER_TEXT (actor)); + if (cursor_pos >= 0) + return cursor_pos; + + /* Cursor is at end */ + buffer = clutter_text_get_buffer (CLUTTER_TEXT (actor)); + return clutter_text_buffer_get_length (buffer); } static gboolean