Ensure the qhelp preview is refreshed after editing#2660
Conversation
This commit fixes a bug in the extension where the qhelp preview was not being refreshed after the first time the preview was rendered. The reason is that vscode will not refresh the markdown preview unless the original file with the markdown in it is already open in the editor. This fix will briefly open the raw markdown, refresh the preview and close the raw markdown.
ed18a2a to
f067c65
Compare
Co-authored-by: Robert <robertbrignull@github.com>
robertbrignull
left a comment
There was a problem hiding this comment.
Unfortunately it isn't quite working as intended for me. See my comment on the code.
I did get it to work on my machine, and I hope it behaves the same for you, but let me know. I haven't used the commands to play around with the vscode editor panels before and I don't know much about them. I found that my suggestion worked mostly by trial and error.
| // Open the raw markdown file as well as the rendered file. | ||
| // This will force the rendered page to refresh if there has been a change to the markdown. | ||
| await window.showTextDocument(uri, { | ||
| viewColumn: ViewColumn.Active, | ||
| }); | ||
| await commandManager.execute("markdown.showPreviewToSide", uri); | ||
| // close the editor we just opened. Users will see a brief flicker of this editor | ||
| // being opened, but doing so will ensure that the preview is refreshed. | ||
| await window.showTextDocument(uri); | ||
| await commandManager.execute("workbench.action.closeActiveEditor"); |
There was a problem hiding this comment.
For me, the markdown file isn't flickering open and then closing again but rather is just sitting open. The left side panel content changes from the qhelp file to the markdown file and then stays like that. It looks like:
Adjusting this to only call showTextDocument once instead of twice makes it work on my machine. Does this also behave the same on your machine, or is there some difference?
| // Open the raw markdown file as well as the rendered file. | |
| // This will force the rendered page to refresh if there has been a change to the markdown. | |
| await window.showTextDocument(uri, { | |
| viewColumn: ViewColumn.Active, | |
| }); | |
| await commandManager.execute("markdown.showPreviewToSide", uri); | |
| // close the editor we just opened. Users will see a brief flicker of this editor | |
| // being opened, but doing so will ensure that the preview is refreshed. | |
| await window.showTextDocument(uri); | |
| await commandManager.execute("workbench.action.closeActiveEditor"); | |
| await commandManager.execute("markdown.showPreviewToSide", uri); | |
| // Open the raw markdown file as well as the rendered file. | |
| // This will force the rendered page to refresh if there has been a change to the markdown. | |
| // Then close the editor we just opened. Users will see a brief flicker of this editor | |
| // being opened, but doing so will ensure that the preview is refreshed. | |
| await window.showTextDocument(uri); | |
| await commandManager.execute("workbench.action.closeActiveEditor"); |
5bba7cb to
d7d1351
Compare
robertbrignull
left a comment
There was a problem hiding this comment.
Tested again and it's working perfectly for me now
|
Thanks! |
This commit fixes a bug in the extension where the qhelp preview was not being refreshed after the first time the preview was rendered. The reason is that vscode will not refresh the markdown preview unless the original file with the markdown in it is already open in the editor.
This fix will briefly open the raw markdown, refresh the preview and close the raw markdown.
Checklist
ready-for-doc-reviewlabel there.