void () { if (myPanel == null || myDocument == null || !myFile.isValid() || isDisposed()) { return; } var html = ReadAction.nonBlocking(() -> { return MarkdownUtil.INSTANCE.generateMarkdownHtml(myFile, myDocument.getText(), myProject); }) .executeSynchronously(); // EA-75860: The lines to the top may be processed slowly; Since we're in pooled thread, we can be disposed already. if (!myFile.isValid() || isDisposed()) { return; } synchronized (REQUESTS_LOCK) { if (mySwingAlarm.isDisposed()) { return; } if (myLastHtmlOrRefreshRequest != null) { mySwingAlarm.cancelRequest(myLastHtmlOrRefreshRequest); } myLastHtmlOrRefreshRequest = () -> { if (myPanel == null) return; String currentHtml = "<html><head></head>" + html + "</html>"; if (!currentHtml.equals(myLastRenderedHtml)) { myLastRenderedHtml = currentHtml; final var fileSystem = myFile.getFileSystem(); myPanel.setHtml(myLastRenderedHtml, mainEditor.getCaretModel().getOffset(), fileSystem.getNioPath(myFile)); } synchronized (REQUESTS_LOCK) { myLastHtmlOrRefreshRequest = null; } }; mySwingAlarm.addRequest(myLastHtmlOrRefreshRequest, RENDERING_DELAY_MS, ModalityState.stateForComponent(getComponent())); } }