Commit 2e801b1ae786326ace0b38293824b90925f0f413

Sam Lantinga 2022-03-04T10:49:12

Split long text input into multiple events if needed (thanks @zreedy!)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
diff --git a/src/events/SDL_keyboard.c b/src/events/SDL_keyboard.c
index 3400ca0..bc2386b 100644
--- a/src/events/SDL_keyboard.c
+++ b/src/events/SDL_keyboard.c
@@ -867,10 +867,14 @@ SDL_SendKeyboardText(const char *text)
     posted = 0;
     if (SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE) {
         SDL_Event event;
+        size_t i = 0, length = SDL_strlen(text);
+
         event.text.type = SDL_TEXTINPUT;
         event.text.windowID = keyboard->focus ? keyboard->focus->id : 0;
-        SDL_utf8strlcpy(event.text.text, text, SDL_arraysize(event.text.text));
-        posted = (SDL_PushEvent(&event) > 0);
+        while (i < length) {
+            i += SDL_utf8strlcpy(event.text.text, text + i, SDL_arraysize(event.text.text));
+            posted |= (SDL_PushEvent(&event) > 0);
+        }
     }
     return (posted);
 }