aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPo Lu2022-01-10 08:40:26 +0800
committerPo Lu2022-01-10 08:40:26 +0800
commit0f5f2af51ecc4a67c1b4875d2af4dc19fdb8e392 (patch)
treec9d5a22cb1d80cbb48000844166fa0a7499105de
parent32f1ec449d760a2a551fb411808d0b4c7d64418c (diff)
downloademacs-0f5f2af51ecc4a67c1b4875d2af4dc19fdb8e392.tar.gz
emacs-0f5f2af51ecc4a67c1b4875d2af4dc19fdb8e392.zip
Fix off-by-one errors in caret position application
* src/gtkutil.c (xg_im_context_preedit_changed): * src/xfns.c (xic_preedit_caret_callback): (xic_preedit_draw_callback): Constrain caret position to SCHARS (arg) - 1.
-rw-r--r--src/gtkutil.c11
-rw-r--r--src/xfns.c22
2 files changed, 18 insertions, 15 deletions
diff --git a/src/gtkutil.c b/src/gtkutil.c
index c47386dae00..8eab6ee723d 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -6090,11 +6090,12 @@ xg_im_context_preedit_changed (GtkIMContext *imc, gpointer user_data)
6090 inev.kind = PREEDIT_TEXT_EVENT; 6090 inev.kind = PREEDIT_TEXT_EVENT;
6091 inev.arg = build_string_from_utf8 (str); 6091 inev.arg = build_string_from_utf8 (str);
6092 6092
6093 Fput_text_property (make_fixnum (min (SCHARS (inev.arg), 6093 if (SCHARS (inev.arg))
6094 max (0, cursor))), 6094 Fput_text_property (make_fixnum (min (SCHARS (inev.arg) - 1,
6095 make_fixnum (min (SCHARS (inev.arg), 6095 max (0, cursor))),
6096 max (0, cursor) + 1)), 6096 make_fixnum (min (SCHARS (inev.arg),
6097 Qcursor, Qt, inev.arg); 6097 max (0, cursor) + 1)),
6098 Qcursor, Qt, inev.arg);
6098 6099
6099 kbd_buffer_store_event (&inev); 6100 kbd_buffer_store_event (&inev);
6100 6101
diff --git a/src/xfns.c b/src/xfns.c
index 7540816416d..9cf6f528198 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -2973,11 +2973,12 @@ xic_preedit_caret_callback (XIC xic, XPointer client_data,
2973 ie.arg = make_string_from_utf8 (output->preedit_chars, 2973 ie.arg = make_string_from_utf8 (output->preedit_chars,
2974 output->preedit_size); 2974 output->preedit_size);
2975 2975
2976 Fput_text_property (make_fixnum (min (SCHARS (ie.arg), 2976 if (SCHARS (ie.arg))
2977 max (0, output->preedit_caret))), 2977 Fput_text_property (make_fixnum (min (SCHARS (ie.arg) - 1,
2978 make_fixnum (max (SCHARS (ie.arg), 2978 max (0, output->preedit_caret))),
2979 max (0, output->preedit_caret) + 1)), 2979 make_fixnum (max (SCHARS (ie.arg),
2980 Qcursor, Qt, ie.arg); 2980 max (0, output->preedit_caret) + 1)),
2981 Qcursor, Qt, ie.arg);
2981 2982
2982 XSETINT (ie.x, 0); 2983 XSETINT (ie.x, 0);
2983 XSETINT (ie.y, 0); 2984 XSETINT (ie.y, 0);
@@ -3196,11 +3197,12 @@ xic_preedit_draw_callback (XIC xic, XPointer client_data,
3196 ie.arg = make_string_from_utf8 (output->preedit_chars, 3197 ie.arg = make_string_from_utf8 (output->preedit_chars,
3197 output->preedit_size); 3198 output->preedit_size);
3198 3199
3199 Fput_text_property (make_fixnum (min (SCHARS (ie.arg), 3200 if (SCHARS (ie.arg))
3200 max (0, output->preedit_caret))), 3201 Fput_text_property (make_fixnum (min (SCHARS (ie.arg) - 1,
3201 make_fixnum (min (SCHARS (ie.arg), 3202 max (0, output->preedit_caret))),
3202 max (0, output->preedit_caret) + 1)), 3203 make_fixnum (min (SCHARS (ie.arg),
3203 Qcursor, Qt, ie.arg); 3204 max (0, output->preedit_caret) + 1)),
3205 Qcursor, Qt, ie.arg);
3204 3206
3205 XSETINT (ie.x, 0); 3207 XSETINT (ie.x, 0);
3206 XSETINT (ie.y, 0); 3208 XSETINT (ie.y, 0);