void (final Project project) { EditorEventMulticaster multicaster = EditorFactory.getInstance().getEventMulticaster(); multicaster.addCaretListener(new CaretListener() { @Override public void caretPositionChanged(@NotNull CaretEvent e) { restartTimer(); } }, this); multicaster.addDocumentListener(new DocumentListener() { @Override public void documentChanged(@NotNull DocumentEvent event) { restartTimer(); } }, this); project.getMessageBus().connect(this).subscribe(ModuleRootListener.TOPIC, new ModuleRootListener() { int beforeCalled; @Override public void beforeRootsChange(@NotNull ModuleRootEvent event) { if (beforeCalled++ == 0) { suspend(); } } @Override public void rootsChanged(@NotNull ModuleRootEvent event) { if (beforeCalled == 0) { return; // This may occur if listener has been added between beforeRootsChange() and rootsChanged() calls. } if (--beforeCalled == 0) { resume(); restartTimer(); } } }); }