void (@NotNull Document document, @NotNull Runnable runnable) { ProgressIndicator currentIndicator = ProgressManager.getInstance().getProgressIndicator(); assert currentIndicator != null; DocumentListener cancellingListener = new DocumentListener() { @Override public void documentChanged(@NotNull DocumentEvent event) { currentIndicator.cancel(); } }; document.addDocumentListener(cancellingListener); try { runnable.run(); } finally { document.removeDocumentListener(cancellingListener); } }