void (@NotNull Runnable runnable, @NotNull ModalityState modality) { AtomicBoolean immediate = new AtomicBoolean(true); IdeEventQueue.getInstance().executeWhenAllFocusEventsLeftTheQueue((ContextAwareRunnable) () -> { if (immediate.get()) { boolean expired = runnable instanceof ExpirableRunnable && ((ExpirableRunnable)runnable).isExpired(); if (!expired) { runnable.run(); } } else { // "Write-safe context" when postponed due to `TransactionGuardImpl#wrapLaterInvocation` ApplicationManager.getApplication().invokeLater((ContextAwareRunnable) () -> doWhenFocusSettlesDown(runnable, modality), modality); } }); immediate.set(false); }