Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to close preview while editor losting focus #2

Open
jamesfancy opened this issue Apr 16, 2017 · 20 comments
Open

Is there a way to close preview while editor losting focus #2

jamesfancy opened this issue Apr 16, 2017 · 20 comments
Labels
Area: Preview The Markdown preview is owned by VS Code. We have nearly no control. Res: External Outside of our control/codebase. Upstream Pertaining to an upstream component, or blocked by an upstream issue.

Comments

@jamesfancy
Copy link

When I was editing a markdown file, I need preview. But when I switch to another editor(such as a js code editor) I hope no markdown preview window appear.

So I hope when I switch to another editor, the markdown preview editr(window) can be closed automatically. If I switch back to the markdown editor, the preview window is opened to side again.

Can you implement that?

@yzhang-gh
Copy link
Owner

That's what I have planned some time ago. 😄

snipaste_20170416_154121

In the long term, the preview behavior might change in future vscode version (e.g. the preview tab might be merged into the Markdown code tab).

And for now, I'll have a try and see if there is a temporary workaround.

@jamesfancy
Copy link
Author

Thank you @neilsustc

e.g. the preview tab might be merged into the Markdown code tab

Great news, I like that feature.

@yzhang-gh
Copy link
Owner

You can find more details about that feature in #22068.

side-by-side preview inside one tab

But I think it will probably take a long time to finish. 😂


I've published v0.5.1 with a temporary solution.
If you switch to a non-Markdown file, it will close all editors in other editor groups (usually the preview tab is in group 2). So it will be OK if you always edit your files in group 1.
Hope you will like.

@jamesfancy
Copy link
Author

@neilsustc v0.5.1 is not strong. Sometime it kept preview editor and closed other editors. I think it should rollback to v0.5.0.

Then let's wait for improvement of markdown extention.

@yzhang-gh
Copy link
Owner

Could you provide any reproduction steps?
If it's hard to solve, I will roll back to previous version as you suggested.

@jamesfancy
Copy link
Author

@neilsustc OK, the steps are simple.

  1. use vscode to open a folder as project
  2. open a .md file (enough big size such as 20KB), the preview editor is opened and rendering.
  3. open a non-md file such as package.json
  4. package.json editor and the md file editor are closed, and the preview pane is still kept.

@yzhang-gh
Copy link
Owner

yzhang-gh commented Apr 17, 2017

I'll rollback to v0.5.0 as there is another user that also found this bug.

@yzhang-gh yzhang-gh added the Upstream Pertaining to an upstream component, or blocked by an upstream issue. label May 31, 2017
@sanjibukai
Copy link

sanjibukai commented Nov 26, 2017

Hello,
As I understand this feature is not yet developed...
Is there a workaround to get the preview closed when focus is lost?
I mean, when the preview is opened it has the same name (ex: Preview file.md), maybe searching for opened tab using that name could help..

BTW, thanks great plugin !

@yzhang-gh
Copy link
Owner

To my knowledge, we can't. Because vscode doesn't provide API to close a editor by name/id.

@yzhang-gh
Copy link
Owner

I can only find vscode commands like closeActiveEditor etc. So I cannot find a workaround for now...

image

@sanjibukai
Copy link

Thanks for the reply...
I think that vscode can bring focus to a newly opened tab (the behavior when a markdown preview is shown), so can it be possible to bring momentarily focus to that tab based on the history of activated tab (or if not possible to track, with some caveat eg. limiting to one opened markdown preview) to close it immediately afterwards (maybe with a callback)?

@yzhang-gh
Copy link
Owner

I get your point now 😂. Yes, it's possible, but really dangerous 🤣.

@yzhang-gh
Copy link
Owner

I tried and as expected it is very unstable and annoying. You won't like it.

@LeBenLeBen
Copy link

This would be an awesome feature. Any chance the API changed since your last tentative? Maybe opening a feature request in https://github.com/microsoft/vscode otherwise?

@yzhang-gh
Copy link
Owner

yzhang-gh commented Oct 4, 2018

To my knowledge, no new APIs 😔

I would suggest posting this "auto-closing" feature request to vscode (rather than API) because the Markdown preview feature is actually implemented by vscode. We have little control over it as an extension.

@Trass3r
Copy link

Trass3r commented Jun 2, 2019

I would suggest posting this "auto-closing" feature request to vscode (rather than API) because the Markdown preview feature is actually implemented by vscode.

Well they still haven't implemented auto-hide of the terminal after all those years and lots of votes, not a good sign 😅
microsoft/vscode#10952

@Trass3r
Copy link

Trass3r commented Jun 2, 2019

Also if I drag an .md file into VSCode with other files already open it does enable the preview on the right but then immediately switches the editor back to the previous one. Has anyone else experienced this?

@Lemmingh Lemmingh added the Res: External Outside of our control/codebase. label Jan 15, 2021
@Lemmingh Lemmingh added the Area: Preview The Markdown preview is owned by VS Code. We have nearly no control. label Aug 24, 2021
@Lemmingh
Copy link
Collaborator

microsoft/vscode#66132

@Gavin-OP
Copy link

Is there any progress on automatically close the preview tab when editor is close?

@LeonardoRick
Copy link

LeonardoRick commented Aug 25, 2024

I don't know how but they managed to do it here: markdown-auto-preview.

It even has an option for closing it when changing file (which I think should be default).

markdown-auto-preview.autoClosePreviewAfterSwitch: Auto close preview window when switch to another tab.

@yzhang-gh maybe you can understand what's being done there and do here as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Preview The Markdown preview is owned by VS Code. We have nearly no control. Res: External Outside of our control/codebase. Upstream Pertaining to an upstream component, or blocked by an upstream issue.
Projects
None yet
Development

No branches or pull requests

8 participants