How to reload editor preview window

I guys, I have attached a small screencast, in which I convert a Markdown document to AsciiDoc. The Markdown has a preview tab, and so has the AsciiDoc document, but after the Markdown document is converted to AsciiDoc, I still see the preview window of the Markdown file, but it's trying to render the AsciiDoc, which fails. When I close the newly converted document and reopen it, then I can succesfully preview the contents of the AsciiDoc.

I'm using the following code for the conversion:

  ApplicationManager.getApplication().runWriteAction(new DocumentRunnable(document, project) {
    @Override
    public void
run() {
      CommandProcessor.getInstance().executeCommand(project, new Runnable() {
        @Override
        public void
run() {

          if (document != null) {
            try {
              String newFileName = FilenameUtils.getBaseName(file.getName()) + ".adoc";
              virtualFile.rename(this, newFileName);

              document.setText(AsciiDocProcessor.convertMarkdownToAsciiDoc(file.getText()));
            }
            catch (IOException e) {
              e.printStackTrace();
            }
          }
        }
      }, getName(), getGroupId(), UndoConfirmationPolicy.REQUEST_CONFIRMATION);
    }
  });
}


But I guess I need to inform IntelliJ that in some way it should reload the preview screen? How can I do such a thing? Or is my document renaming (and document text replacement) incorrect?

Thanks,

Erik



Attachment(s):
bug.gif
4 comments
Comment actions Permalink

This behavior looks like a bug in the Markdown plugin to me; specifically the MarkdownPreviewEditor.isValid() method is not properly implemented. It needs to check that the virtual file is valid and that its file type is still Markdown.

0
Comment actions Permalink

Hi Dmitry,

Thanks for your response. It will be tricky for me to fix that. Is there maybe a workaround to force the reload of the file, or some other solution?

Erik

0
Comment actions Permalink

Why would it be tricky? The plugin is open-source; it's easy to send a pull request.

0
Comment actions Permalink

Sure, I'll try.

It's just that the plugin isn't very active, and there are already lots of open issues, and some open pull requests.
Besides that, I'm building an alternative for the Markdown plugin, it feels a bit weird to do pull requests on it then.

0

Please sign in to leave a comment.