@@ -60,8 +60,7 @@ static NativeEngine *_singleton = NULL;
60
60
// workaround for internal bug b/149866792
61
61
static NativeEngineSavedState appState = {false };
62
62
63
- static std::string textInputBuffer;
64
- static bool firstInput;
63
+ static std::wstring textInputBuffer;
65
64
66
65
67
66
NativeEngine::NativeEngine (struct android_app *app) {
@@ -92,8 +91,7 @@ NativeEngine::NativeEngine(struct android_app *app) {
92
91
// https://developer.android.com/reference/android/view/inputmethod/EditorInfo
93
92
constexpr int IME_ACTION_NONE = 1 ;
94
93
constexpr int IME_FLAG_NO_FULLSCREEN = 33554432 ;
95
-
96
- // TODO: add support to input suggestions
94
+
97
95
GameActivity_setImeEditorInfo (app->activity , InputType_dot_TYPE_CLASS_TEXT, IME_ACTION_NONE, IME_FLAG_NO_FULLSCREEN);
98
96
99
97
if (app->savedState != NULL ) {
@@ -168,14 +166,16 @@ int NativeEngine::getScreenDensity(){
168
166
return mScreenDensity ;
169
167
}
170
168
171
- void NativeEngine::showSoftInput (){
172
- textInputBuffer = " " ;
173
- firstInput = true ;
169
+ void NativeEngine::showSoftInput (std::wstring text){
170
+ textInputBuffer = text;
171
+
172
+ std::wstring_convert<std::codecvt_utf8_utf16<wchar_t >> convert;
173
+ std::string strInputBuffer = convert.to_bytes (textInputBuffer);
174
174
175
- mGameTextInputState .text_UTF8 = textInputBuffer .data ();
176
- mGameTextInputState .text_length = textInputBuffer .length ();
177
- mGameTextInputState .selection .start = textInputBuffer .length ();
178
- mGameTextInputState .selection .end = textInputBuffer .length ();
175
+ mGameTextInputState .text_UTF8 = strInputBuffer .data ();
176
+ mGameTextInputState .text_length = strInputBuffer .length ();
177
+ mGameTextInputState .selection .start = strInputBuffer .length ();
178
+ mGameTextInputState .selection .end = strInputBuffer .length ();
179
179
mGameTextInputState .composingRegion .start = -1 ;
180
180
mGameTextInputState .composingRegion .end = -1 ;
181
181
@@ -248,20 +248,28 @@ void NativeEngine::gameLoop() {
248
248
if (mApp ->textInputState ) {
249
249
GameActivity_getTextInputState (mApp ->activity , [](void *context, const GameTextInputState *state) {
250
250
if (!context || !state) return ;
251
- if (textInputBuffer.length () < state->text_length ) {
252
- // text_length is different from utf16Text.length and state->(selection or composingRegion) with unicode chars
253
- if (state->text_length > 0 ) {
254
- std::wstring_convert<std::codecvt_utf8_utf16<wchar_t > > convert;
255
- std::wstring utf16Text = convert.from_bytes (state->text_UTF8 );
256
-
257
- // getting only the last character
258
- Supernova::Engine::systemCharInput (utf16Text.back ());
259
- }
260
- }else if (!firstInput){
251
+
252
+ std::wstring_convert<std::codecvt_utf8_utf16<wchar_t >> convert;
253
+ std::wstring utf16Text = convert.from_bytes (state->text_UTF8 );
254
+
255
+ while (textInputBuffer.length () > utf16Text.length ()){
256
+ textInputBuffer.pop_back ();
261
257
Supernova::Engine::systemCharInput (' \b ' );
262
258
}
263
- textInputBuffer = std::string (state->text_UTF8 , state->text_length );
264
- firstInput = false ;
259
+
260
+ int pos = 0 ;
261
+ while (textInputBuffer[pos] == utf16Text[pos] and pos < textInputBuffer.length ()){
262
+ pos++;
263
+ }
264
+
265
+ for (int i = pos; i < textInputBuffer.length (); i++){
266
+ Supernova::Engine::systemCharInput (' \b ' );
267
+ }
268
+ for (int i = pos; i < utf16Text.length (); i++){
269
+ Supernova::Engine::systemCharInput (utf16Text[i]);
270
+ }
271
+ textInputBuffer = utf16Text;
272
+
265
273
}, this );
266
274
mApp ->textInputState = 0 ;
267
275
}
0 commit comments