mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-16 05:34:00 -04:00
ime: fix rendering of pre-edit cursor when positioned after the pre-edit string
We failed to convert the byte-indices to cell indices, resulting in a box cursor covering the entire pre-edit string. Note that in addition to fixing the translation from byte index to cell index, the rendered had to be updated to dirty one extra cell from the original grid. Without this, we left trailing cursors behind us when the user deleted text from the pre-edit string.
This commit is contained in:
parent
f9a43209f2
commit
adbf036053
3 changed files with 25 additions and 9 deletions
19
ime.c
19
ime.c
|
|
@ -194,6 +194,8 @@ done(void *data, struct zwp_text_input_v3 *zwp_text_input_v3,
|
|||
cell_idx += width;
|
||||
}
|
||||
|
||||
const size_t byte_len = strlen(seat->ime.preedit.pending.text);
|
||||
|
||||
/* Pre-edit cursor - hidden */
|
||||
if (seat->ime.preedit.pending.cursor_begin == -1 ||
|
||||
seat->ime.preedit.pending.cursor_end == -1)
|
||||
|
|
@ -206,6 +208,15 @@ done(void *data, struct zwp_text_input_v3 *zwp_text_input_v3,
|
|||
term->ime.preedit.cursor.end = -1;
|
||||
}
|
||||
|
||||
else if (seat->ime.preedit.pending.cursor_begin == byte_len &&
|
||||
seat->ime.preedit.pending.cursor_end == byte_len)
|
||||
{
|
||||
/* Cursor is *after* the entire pre-edit string */
|
||||
term->ime.preedit.cursor.hidden = false;
|
||||
term->ime.preedit.cursor.start = cell_count;
|
||||
term->ime.preedit.cursor.end = cell_count;
|
||||
}
|
||||
|
||||
else {
|
||||
/*
|
||||
* Translate cursor position to cell indices
|
||||
|
|
@ -220,16 +231,8 @@ done(void *data, struct zwp_text_input_v3 *zwp_text_input_v3,
|
|||
*
|
||||
* When we find the matching *byte* index, we at the same
|
||||
* time know both the unicode *and* cell index.
|
||||
*
|
||||
* Note that this has only been tested with
|
||||
*
|
||||
* cursor_begin == cursor_end == 0
|
||||
*
|
||||
* I haven't found an IME that requests anything else
|
||||
*/
|
||||
|
||||
const size_t byte_len = strlen(seat->ime.preedit.pending.text);
|
||||
|
||||
int cell_begin = -1, cell_end = -1;
|
||||
for (size_t byte_idx = 0, wc_idx = 0, cell_idx = 0;
|
||||
byte_idx < byte_len &&
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue