Input methods cannot retrieve surrounding texts correctly from ClutterText
Affected version
- Fedora 40
- Mutter 46.0
- XOrg and Wayland
Affected input methods
A list of known input methods that use surrounding texts for text input:
- ibus-bamboo (by selecting the 'Surrounding Text' mode from the keyboard menu in the top bar)
- ibus-hangul (by setting /org/freedesktop/ibus/engine/hangul/preedit-mode to 'none' with gsetting)
- ibus-hiragana (by default)
Bug summary
Input methods cannot retrieve surrounding texts correctly that are typed in ClutterText, such as the 'Type to search' box in GNOME Shell.
What happened
Input methods receive the "set-surrounding-text" signals with cursor and anchor positions as byte offsets from ClutterText. However, input methods expect cursor and anchor positions to be provided as character offsets, as described in #3102.
Relevant logs, screenshots, screencasts etc.
The following patch appears to fix this issue:
--- a/clutter/clutter/clutter-text.c
+++ b/clutter/clutter/clutter-text.c
@@ -336,8 +336,8 @@ clutter_text_input_focus_request_surrounding (ClutterInputFocus *focus)
anchor_pos = cursor_pos;
clutter_input_focus_set_surrounding (focus, text,
- g_utf8_offset_to_pointer (text, cursor_pos) - text,
- g_utf8_offset_to_pointer (text, anchor_pos) - text);
+ cursor_pos,
+ anchor_pos);
}
static void
Note that clutter_input_focus_set_surrounding() currently expects cursor and anchor positions to be provided as character offsets.
Also, please note that this issue needs to be fixed to test and address gnome-shell#7592.
Edited by Shiki Okasaka