From 29cb340db9d5853ee25589735be99279aba0c073 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Thu, 2 Jun 2016 19:23:05 +0300 Subject: [PATCH] followup to IDEA-CR-11042 --- .../src/com/intellij/ide/IdeEventQueue.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java index 7b107da1bdf6..885292be3d7a 100644 --- a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java +++ b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java @@ -160,6 +160,15 @@ public class IdeEventQueue extends EventQueue { } private void abracadabraDaberBoreh() { + // we need to track if there are KeyBoardEvents in IdeEventQueue + // so we want to intercept all events posted to IdeEventQueue and increment counters + // However, we regular control flow goes like this: + // PostEventQueue.flush() -> EventQueue.postEvent() -> IdeEventQueue.postEventPrivate() -> AAAA we missed event, because postEventPrivate() can't be overridden. + // Instead, we do following: + // - create new PostEventQueue holding our IdeEventQueue instead of old EventQueue + // - replace "PostEventQueue" value in AppContext with this new PostEventQueue + // since that the control flow goes like this: + // PostEventQueue.flush() -> IdeEventQueue.postEvent() -> We intercepted event, incremented counters. try { Class aClass = Class.forName("sun.awt.PostEventQueue"); Constructor constructor = aClass.getDeclaredConstructor(EventQueue.class); @@ -536,7 +545,7 @@ public class IdeEventQueue extends EventQueue { Application app = ApplicationManager.getApplication(); boolean weAreNotActive = app == null || !app.isActive(); - weAreNotActive |=(e instanceof FocusEvent && ((FocusEvent)e).getOppositeComponent() == null); + weAreNotActive |= e instanceof FocusEvent && ((FocusEvent)e).getOppositeComponent() == null; if (weAreNotActive) { myWinMetaPressed = false; return e; @@ -1149,7 +1158,7 @@ public class IdeEventQueue extends EventQueue { } private static boolean isKeyboardEvent(@NotNull AWTEvent event) { - return event instanceof KeyEvent && (event.getID() == KeyEvent.KEY_PRESSED || event.getID() == KeyEvent.KEY_RELEASED || event.getID() == KeyEvent.KEY_TYPED); + return event instanceof KeyEvent; } @Override