summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2022-12-20 02:40:14 +0000
committerMatthias Clasen <mclasen@redhat.com>2022-12-20 02:40:14 +0000
commita920c0d2de90d6fb86ad141bb30de32f7cafd9a3 (patch)
treec9de5c46ec743463062d1910a3bc56ce96fea697
parent98bb14a84952c4f6b9783706011db0079619cf6b (diff)
parentad83d616c4b66a5681a239f0a2e57bb7f3220e7b (diff)
downloadgtk+-a920c0d2de90d6fb86ad141bb30de32f7cafd9a3.tar.gz
Merge branch 'wip/gtk4-fix-delete-surrounding' into 'main'
gtkimcontextwayland: Convert byte based offset to char based offset in delete_surrounding_text See merge request GNOME/gtk!5254
-rw-r--r--gtk/gtkimcontextwayland.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/gtk/gtkimcontextwayland.c b/gtk/gtkimcontextwayland.c
index 439c64bd3b..29e8a53cbf 100644
--- a/gtk/gtkimcontextwayland.c
+++ b/gtk/gtkimcontextwayland.c
@@ -238,14 +238,24 @@ text_input_delete_surrounding_text (void *data,
{
GtkIMContextWaylandGlobal *global = data;
GtkIMContextWayland *context;
+ char *cursor_pointer;
+ uint32_t char_before_length;
+ uint32_t char_after_length;
if (!global->current)
return;
context = GTK_IM_CONTEXT_WAYLAND (global->current);
- context->pending_surrounding_delete.before_length = before_length;
- context->pending_surrounding_delete.after_length = after_length;
+ /* We already got byte lengths from text_input_v3, but GTK uses char lengths
+ * for delete_surrounding, So convert it here.
+ */
+ cursor_pointer = context->surrounding.text + context->surrounding.cursor_idx;
+ char_before_length = g_utf8_pointer_to_offset (cursor_pointer - before_length, cursor_pointer);
+ char_after_length = g_utf8_pointer_to_offset (cursor_pointer, cursor_pointer + after_length);
+
+ context->pending_surrounding_delete.before_length = char_before_length;
+ context->pending_surrounding_delete.after_length = char_after_length;
}
static void