diff --git a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java index 1807e54e37da..57f3bf6d035d 100644 --- a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java +++ b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java @@ -144,11 +144,16 @@ public class IdeEventQueue extends EventQueue { }, runnable); } + public String runnablesWaitingForFocusChangeState() { + return "Focus event list (trying to execute runnable): " + focusEventsList.stream(). + collect(StringBuilder::new, (builder, event) -> builder.append(", [").append(event.getID()).append("; ") + .append(event.getSource().getClass().getName()).append("]"), StringBuilder::append); + } + private void ifFocusEventsInTheQueue(Consumer yes, Runnable no) { if (!focusEventsList.isEmpty()) { - FOCUS_AWARE_RUNNABLES_LOG.debug("Focus event list (trying to execute runnable): " + focusEventsList.stream(). - collect(StringBuilder::new, (builder, event) -> builder.append(", [" + event.getID() + "; " + event.getSource().getClass().getName() + "]"), StringBuilder::append)); + FOCUS_AWARE_RUNNABLES_LOG.debug(runnablesWaitingForFocusChangeState()); // find the latest focus gained Optional first = focusEventsList.stream(). @@ -161,7 +166,7 @@ public class IdeEventQueue extends EventQueue { yes.accept(first.get()); } else { - FOCUS_AWARE_RUNNABLES_LOG.debug(" runnable is run right away : " + no.getClass().getName()); + FOCUS_AWARE_RUNNABLES_LOG.debug(" runnable is run on EDT if needed : " + no.getClass().getName()); UIUtil.invokeLaterIfNeeded(no); } } @@ -441,7 +446,7 @@ public class IdeEventQueue extends EventQueue { FOCUS_AWARE_RUNNABLES_LOG.debug("Focus event list (execute on focus event): " + focusEventsList.stream(). collect(StringBuilder::new, (builder, event) -> builder.append(", [" + event.getID() + "; " + event.getSource().getClass().getName() + "]"), StringBuilder::append)); StreamEx.of(focusEventsList). - takeWhile(entry -> entry.equals(finalEvent)). + takeWhileInclusive(entry -> !entry.equals(finalEvent)). collect(Collectors.toList()).stream().map(entry -> { focusEventsList.remove(entry); return myRunnablesWaitingFocusChange.remove(entry); diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/FocusManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/FocusManagerImpl.java index 6543ad5f4386..6d8fd27fef0e 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/FocusManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/FocusManagerImpl.java @@ -235,7 +235,9 @@ public class FocusManagerImpl extends IdeFocusManager implements Disposable { new Exception() { @Override public String getMessage() { - return "Time: " + (System.currentTimeMillis() - currentTime) + "; cause: " + cause; + return "Time: " + (System.currentTimeMillis() - currentTime) + "; cause: " + cause + + "; runnable waiting for the focus change: " + + IdeEventQueue.getInstance().runnablesWaitingForFocusChangeState(); } }, true).doWhenProcessed(() -> {