Skip to content

Ensure the qhelp preview is refreshed after editing#2660

Merged
aeisenberg merged 3 commits intomainfrom
aeisenberg/qhelp-preview
Aug 3, 2023
Merged

Ensure the qhelp preview is refreshed after editing#2660
aeisenberg merged 3 commits intomainfrom
aeisenberg/qhelp-preview

Conversation

@aeisenberg
Copy link
Copy Markdown
Contributor

@aeisenberg aeisenberg commented Jul 31, 2023

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

  • CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • Issues have been created for any UI or other user-facing changes made by this pull request.
  • [Maintainers only] If this pull request makes user-facing changes that require documentation changes, open a corresponding docs pull request in the github/codeql repo and add the ready-for-doc-review label there.

@aeisenberg aeisenberg requested a review from a team as a code owner July 31, 2023 23:19
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.
@aeisenberg aeisenberg force-pushed the aeisenberg/qhelp-preview branch from ed18a2a to f067c65 Compare July 31, 2023 23:21
Co-authored-by: Robert <robertbrignull@github.com>
Copy link
Copy Markdown
Contributor

@robertbrignull robertbrignull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +77 to +84
// 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");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Screenshot 2023-08-02 at 10 27 29

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?

Suggested change
// 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");

@aeisenberg aeisenberg force-pushed the aeisenberg/qhelp-preview branch from 5bba7cb to d7d1351 Compare August 2, 2023 19:32
Copy link
Copy Markdown
Contributor

@robertbrignull robertbrignull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested again and it's working perfectly for me now

@aeisenberg
Copy link
Copy Markdown
Contributor Author

Thanks!

@aeisenberg aeisenberg merged commit 87bbf29 into main Aug 3, 2023
@aeisenberg aeisenberg deleted the aeisenberg/qhelp-preview branch August 3, 2023 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants