ime: wayland: Make use of `SDL_TEXTEDITING_EXT`
Because we were sending multiple chunks of preedit strings, `SDL_SendEditingText` was using the old `SDL_TEXTEDITING` event only. Now if `SDL_HINT_IME_SUPPORT_EXTENDED_TEXT` is enabled, we send the full string and correctly set the cursor position and selection size.main
parent
74bcc5a0a3
commit
d11702ce29
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
#include "SDL_stdinc.h"
|
#include "SDL_stdinc.h"
|
||||||
#include "SDL_timer.h"
|
#include "SDL_timer.h"
|
||||||
|
#include "SDL_hints.h"
|
||||||
|
|
||||||
#include "../../core/unix/SDL_poll.h"
|
#include "../../core/unix/SDL_poll.h"
|
||||||
#include "../../events/SDL_sysevents.h"
|
#include "../../events/SDL_sysevents.h"
|
||||||
|
@ -1554,18 +1555,33 @@ text_input_preedit_string(void *data,
|
||||||
char buf[SDL_TEXTEDITINGEVENT_TEXT_SIZE];
|
char buf[SDL_TEXTEDITINGEVENT_TEXT_SIZE];
|
||||||
text_input->has_preedit = SDL_TRUE;
|
text_input->has_preedit = SDL_TRUE;
|
||||||
if (text) {
|
if (text) {
|
||||||
size_t text_bytes = SDL_strlen(text), i = 0;
|
if (SDL_GetHintBoolean(SDL_HINT_IME_SUPPORT_EXTENDED_TEXT, SDL_FALSE)) {
|
||||||
size_t cursor = 0;
|
size_t cursor_begin_utf8 = cursor_begin >= 0 ? SDL_utf8strnlen(text, cursor_begin) : -1;
|
||||||
|
size_t cursor_end_utf8 = cursor_end >= 0 ? SDL_utf8strnlen(text, cursor_end) : -1;
|
||||||
|
size_t cursor_size_utf8;
|
||||||
|
if (cursor_end_utf8 >= 0) {
|
||||||
|
if (cursor_begin_utf8 >= 0) {
|
||||||
|
cursor_size_utf8 = cursor_end_utf8 - cursor_begin_utf8;
|
||||||
|
} else {
|
||||||
|
cursor_size_utf8 = cursor_end_utf8;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cursor_size_utf8 = -1;
|
||||||
|
}
|
||||||
|
SDL_SendEditingText(text, cursor_begin_utf8, cursor_size_utf8);
|
||||||
|
} else {
|
||||||
|
size_t text_bytes = SDL_strlen(text), i = 0;
|
||||||
|
size_t cursor = 0;
|
||||||
|
do {
|
||||||
|
const size_t sz = SDL_utf8strlcpy(buf, text+i, sizeof(buf));
|
||||||
|
const size_t chars = SDL_utf8strlen(buf);
|
||||||
|
|
||||||
do {
|
SDL_SendEditingText(buf, cursor, chars);
|
||||||
const size_t sz = SDL_utf8strlcpy(buf, text+i, sizeof(buf));
|
|
||||||
const size_t chars = SDL_utf8strlen(buf);
|
|
||||||
|
|
||||||
SDL_SendEditingText(buf, cursor, chars);
|
i += sz;
|
||||||
|
cursor += chars;
|
||||||
i += sz;
|
} while (i < text_bytes);
|
||||||
cursor += chars;
|
}
|
||||||
} while (i < text_bytes);
|
|
||||||
} else {
|
} else {
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
SDL_SendEditingText(buf, 0, 0);
|
SDL_SendEditingText(buf, 0, 0);
|
||||||
|
|
Loading…
Reference in New Issue