clutter: Fix ClutterText ::delete-surrounding IM implementation

The clutter_text_delete_text() function used underneath expects character
offsets for both start/end position. Fix the end position passed an offset
instead of that, and compesnate for the cursor position being always -1
when the caret is at the end of the string.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2384>
This commit is contained in:
Carlos Garnacho 2022-04-22 17:56:00 +02:00
parent cfdca246f2
commit b4cdf5e098

View File

@ -356,10 +356,16 @@ clutter_text_input_focus_delete_surrounding (ClutterInputFocus *focus,
guint len) guint len)
{ {
ClutterText *clutter_text = CLUTTER_TEXT_INPUT_FOCUS (focus)->text; ClutterText *clutter_text = CLUTTER_TEXT_INPUT_FOCUS (focus)->text;
ClutterTextBuffer *buffer;
int cursor; int cursor;
int start; int start;
buffer = get_buffer (clutter_text);
cursor = clutter_text_get_cursor_position (clutter_text); cursor = clutter_text_get_cursor_position (clutter_text);
if (cursor < 0)
cursor = clutter_text_buffer_get_length (buffer);
start = cursor + offset; start = cursor + offset;
if (start < 0) if (start < 0)
{ {
@ -368,7 +374,7 @@ clutter_text_input_focus_delete_surrounding (ClutterInputFocus *focus,
return; return;
} }
if (clutter_text_get_editable (clutter_text)) if (clutter_text_get_editable (clutter_text))
clutter_text_delete_text (clutter_text, start, len); clutter_text_delete_text (clutter_text, start, start + len);
} }
static void static void