@@ -271,6 +271,7 @@ public void removeNotify() {
271
271
nativeEndComposition (getNativeViewPtr (fAwtFocussedComponentPeer ));
272
272
}
273
273
274
+ fAwtFocussedComponent = null ;
274
275
fAwtFocussedComponentPeer = null ;
275
276
}
276
277
@@ -281,34 +282,32 @@ public void removeNotify() {
281
282
* to talk to when responding to key events.
282
283
*/
283
284
protected void setAWTFocussedComponent (Component component ) {
284
- LWComponentPeer <?, ?> peer = null ;
285
- long modelPtr = 0 ;
286
- CInputMethod imInstance = this ;
287
-
288
- // component will be null when we are told there's no focused component.
289
- // When that happens we need to notify the native architecture to stop generating IMEs
290
- if (component == null ) {
291
- peer = fAwtFocussedComponentPeer ;
292
- imInstance = null ;
293
- } else {
294
- peer = getNearestNativePeer (component );
285
+ if (component == null || component == fAwtFocussedComponent ) {
286
+ // Sometimes input happens for the natively unfocused window
287
+ // (e.g. in case of system emoji picker),
288
+ // so we don't reset last focused component on focus lost.
289
+ return ;
290
+ }
291
+
292
+ if (fAwtFocussedComponentPeer != null ) {
293
+ long modelPtr = getNativeViewPtr (fAwtFocussedComponentPeer );
294
+ nativeNotifyPeer (modelPtr , null );
295
+ }
296
+
297
+ fAwtFocussedComponent = component ;
298
+ fAwtFocussedComponentPeer = getNearestNativePeer (component );
299
+
300
+ if (fAwtFocussedComponentPeer != null ) {
301
+ long modelPtr = getNativeViewPtr (fAwtFocussedComponentPeer );
295
302
303
+ CInputMethod imInstance = this ;
296
304
// If we have a passive client, don't pass input method events to it.
297
305
if (component .getInputMethodRequests () == null ) {
298
306
imInstance = null ;
299
307
}
300
- }
301
308
302
- if (peer != null ) {
303
- modelPtr = getNativeViewPtr (peer );
304
-
305
- // modelPtr refers to the ControlModel that either got or lost focus.
306
309
nativeNotifyPeer (modelPtr , imInstance );
307
310
}
308
-
309
- // Track the focused component and its nearest peer.
310
- fAwtFocussedComponent = component ;
311
- fAwtFocussedComponentPeer = getNearestNativePeer (component );
312
311
}
313
312
314
313
/**
0 commit comments