@@ -229,6 +229,14 @@ export class InnerPlayer {
229
229
"input" ,
230
230
this . virtualKeyboardInput . bind ( this ) ,
231
231
) ;
232
+ this . virtualKeyboard . addEventListener (
233
+ "compositionupdate" ,
234
+ this . virtualKeyboardCompositionUpdate . bind ( this ) ,
235
+ ) ;
236
+ this . virtualKeyboard . addEventListener (
237
+ "compositionend" ,
238
+ this . virtualKeyboardCompositionEnd . bind ( this ) ,
239
+ ) ;
232
240
this . saveManager = this . shadow . getElementById (
233
241
"save-manager" ,
234
242
) ! as HTMLDivElement ;
@@ -1252,10 +1260,15 @@ export class InnerPlayer {
1252
1260
}
1253
1261
}
1254
1262
1255
- private virtualKeyboardInput ( ) {
1256
- const input = this . virtualKeyboard ;
1257
- const string = input . value ;
1258
- for ( const char of string ) {
1263
+ private virtualKeyboardInput ( e : Event ) {
1264
+ const event = e as InputEvent ;
1265
+ if ( ! event || event . isComposing || event . inputType === 'insertCompositionText' ) {
1266
+ // Ignore composing events, we'll get the composed text at the end
1267
+ return ;
1268
+ }
1269
+
1270
+ const text = event . data || "" ;
1271
+ for ( const char of text ) {
1259
1272
for ( const eventType of [ "keydown" , "keyup" ] ) {
1260
1273
this . element . dispatchEvent (
1261
1274
new KeyboardEvent ( eventType , {
@@ -1265,7 +1278,24 @@ export class InnerPlayer {
1265
1278
) ;
1266
1279
}
1267
1280
}
1268
- input . value = "" ;
1281
+ this . virtualKeyboard . value = "" ;
1282
+ }
1283
+
1284
+ private virtualKeyboardCompositionUpdate ( e : Event ) {
1285
+ const event = e as CompositionEvent ;
1286
+ // TODO Add support for moving cursor during IME,
1287
+ // we cannot use selectionStart & selectionEnd here,
1288
+ // as they lag behind and don't take into account
1289
+ // moving the caret with arrows.
1290
+ const text = event . data || "" ;
1291
+ this . instance ?. handle_ime_preedit ( text , text . length , text . length ) ;
1292
+ }
1293
+
1294
+ private virtualKeyboardCompositionEnd ( e : Event ) {
1295
+ const event = e as CompositionEvent ;
1296
+ this . instance ?. handle_ime_preedit ( "" , 0 , 0 ) ;
1297
+ this . instance ?. handle_ime_commit ( event . data || "" ) ;
1298
+ this . virtualKeyboard . value = "" ;
1269
1299
}
1270
1300
1271
1301
protected openVirtualKeyboard ( ) : void {
0 commit comments