wl: the text before the cursor, and the runes to take back

The surrounding_text event was taken and thrown away.  It carries the
text around the cursor with a byte offset into it, and belongs to the
activation like the content type, so it is pending until done and
starts empty at every activate.  delete_surrounding_text counts bytes
where the engine counts runes, and the frontend holds the text those
runes are in, so it measures them itself.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-18 14:31:44 +09:00
parent 921e632eae
commit 5d9a2a614e
4 changed files with 59 additions and 1 deletions

View File

@@ -129,4 +129,5 @@ void xim_adapter_callback_owner_loss(struct ct*);
void xim_adapter_commit_encoding(struct ct*);
void wl_modifier_mask(struct ct*);
void wl_forwarded_keys(struct ct*);
void wl_surrounding_text(struct ct*);
void wl_repeat_ends(struct ct*);

View File

@@ -149,6 +149,7 @@ static const struct ct_test tests[] = {
{ "xim/commit-encoding", xim_adapter_commit_encoding },
{ "wl/modifier-mask", wl_modifier_mask },
{ "wl/forwarded-keys", wl_forwarded_keys },
{ "wl/surrounding-text", wl_surrounding_text },
{ "wl/repeat-ends", wl_repeat_ends },
};
#else

View File

@@ -107,6 +107,30 @@ wl_forwarded_keys(struct ct *t)
* Arming a repeat needs the engine, which is not here; ending one does
* not, and a repeat that outlives its key is the worst this can do.
*/
/*
* The text before the cursor is what a reading may reach into, and a
* take-back is measured in the bytes those runes hold.
*/
void
wl_surrounding_text(struct ct *t)
{
sclear(&pendingsurround);
imsurrounding(nil, nil, "가나다라", 9, 9);
checkstr(t, "the text before the cursor", "가나다", &pendingsurround);
surround = pendingsurround;
CT_EQ_INT(t, 3, backbytes(1));
CT_EQ_INT(t, 6, backbytes(2));
CT_EQ_INT(t, 9, backbytes(9));
CT_EQ_INT(t, 0, backbytes(0));
/* A cursor past the end of the buffer is the whole of it. */
imsurrounding(nil, nil, "ab", 99, 99);
checkstr(t, "a cursor past the end", "ab", &pendingsurround);
/* An activation starts with none, whatever the last one had. */
imactivate(nil, nil);
CT_EQ_INT(t, 0, pendingsurround.n);
sclear(&surround);
}
void
wl_repeat_ends(struct ct *t)
{