[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 0f5f2af51e 1/2: Fix off-by-one errors in caret position applicati
From: |
Po Lu |
Subject: |
master 0f5f2af51e 1/2: Fix off-by-one errors in caret position application |
Date: |
Sun, 9 Jan 2022 20:06:26 -0500 (EST) |
branch: master
commit 0f5f2af51ecc4a67c1b4875d2af4dc19fdb8e392
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>
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.
---
src/gtkutil.c | 11 ++++++-----
src/xfns.c | 22 ++++++++++++----------
2 files changed, 18 insertions(+), 15 deletions(-)
diff --git a/src/gtkutil.c b/src/gtkutil.c
index c47386dae0..8eab6ee723 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -6090,11 +6090,12 @@ xg_im_context_preedit_changed (GtkIMContext *imc,
gpointer user_data)
inev.kind = PREEDIT_TEXT_EVENT;
inev.arg = build_string_from_utf8 (str);
- Fput_text_property (make_fixnum (min (SCHARS (inev.arg),
- max (0, cursor))),
- make_fixnum (min (SCHARS (inev.arg),
- max (0, cursor) + 1)),
- Qcursor, Qt, inev.arg);
+ if (SCHARS (inev.arg))
+ Fput_text_property (make_fixnum (min (SCHARS (inev.arg) - 1,
+ max (0, cursor))),
+ make_fixnum (min (SCHARS (inev.arg),
+ max (0, cursor) + 1)),
+ Qcursor, Qt, inev.arg);
kbd_buffer_store_event (&inev);
diff --git a/src/xfns.c b/src/xfns.c
index 7540816416..9cf6f52819 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -2973,11 +2973,12 @@ xic_preedit_caret_callback (XIC xic, XPointer
client_data,
ie.arg = make_string_from_utf8 (output->preedit_chars,
output->preedit_size);
- Fput_text_property (make_fixnum (min (SCHARS (ie.arg),
- max (0,
output->preedit_caret))),
- make_fixnum (max (SCHARS (ie.arg),
- max (0, output->preedit_caret)
+ 1)),
- Qcursor, Qt, ie.arg);
+ if (SCHARS (ie.arg))
+ Fput_text_property (make_fixnum (min (SCHARS (ie.arg) - 1,
+ max (0,
output->preedit_caret))),
+ make_fixnum (max (SCHARS (ie.arg),
+ max (0,
output->preedit_caret) + 1)),
+ Qcursor, Qt, ie.arg);
XSETINT (ie.x, 0);
XSETINT (ie.y, 0);
@@ -3196,11 +3197,12 @@ xic_preedit_draw_callback (XIC xic, XPointer
client_data,
ie.arg = make_string_from_utf8 (output->preedit_chars,
output->preedit_size);
- Fput_text_property (make_fixnum (min (SCHARS (ie.arg),
- max (0, output->preedit_caret))),
- make_fixnum (min (SCHARS (ie.arg),
- max (0, output->preedit_caret) +
1)),
- Qcursor, Qt, ie.arg);
+ if (SCHARS (ie.arg))
+ Fput_text_property (make_fixnum (min (SCHARS (ie.arg) - 1,
+ max (0, output->preedit_caret))),
+ make_fixnum (min (SCHARS (ie.arg),
+ max (0, output->preedit_caret) +
1)),
+ Qcursor, Qt, ie.arg);
XSETINT (ie.x, 0);
XSETINT (ie.y, 0);