microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.23k stars 28.56k forks source link

Markdown preview is not automatically opened when md file is opened via command-line and no VS code instance was already running #197374

Open jpstotz opened 10 months ago

jpstotz commented 10 months ago

Does this issue occur when all extensions are disabled?: Yes

I read various topics on how to achieve that Markdown files are automatically displayed as preview (e.g. #2766, https://stackoverflow.com/a/63541437/150978).

The only partial working solution was adding in setting.json

    "workbench.editorAssociations": {
        "*.md": "vscode.markdown.preview.editor"
    }

However this only works if VS code is already running. If no VS code instance is running and you execute code C:\<somepath>\test.md then the md file is opened in edit view and not preview mode.

Version: 1.84.0 (user setup)
Commit: d037ac076cee195194f93ce6fe2bdfe2969cc82d
Date: 2023-11-01T11:29:04.398Z
Electron: 25.9.2
ElectronBuildId: 24603566
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Windows_NT x64 10.0.19045

Steps to Reproduce:

  1. Change the setting change shown above.
  2. Create a simple markup file C:\temp\test.md
  3. Close all open VS code instances
  4. Execute code C:\temp\test.md
  5. VS code opens and show the editor of the md file

If you repeat the steps but in step 3 do not close all VS code instances, but have one instance running in step 5 correctly the preview will be displayed.

Why does it make a difference if a VS code instance is already running or not? It should not make a diference, so the current behavior is not deterministic which in my opinion means it is a bug.

manav014 commented 1 month ago

I tried reproducing this issue with the latest stable release using following configuration.

Version: 1.91.1
Commit: f1e16e1e6214d7c44d078b1f0607b2388f29d729
Date: 2024-07-09T22:07:46.768Z
Electron: 29.4.0
ElectronBuildId: 9728852
Chromium: 122.0.6261.156
Node.js: 20.9.0
V8: 12.2.281.27-electron.0
OS: Darwin arm64 23.5.0

And I couldn't reproduced the issue. Steps I followed to reproduce are as follows:

  1. Set the editorAssociations setting in user settings.
  2. Force quit all instances of VS Code running.
  3. Open a .md file using code command.
  4. The .md file was opened in preview mode itself. PFA - POC video

https://github.com/user-attachments/assets/bc8607ae-a34c-4960-b5f0-9bd1cfa55240

jpstotz commented 1 month ago

Just retried it on a different Windows 11 system and the behavior is mostly as described in my initial post: md file is opened only in editor view.

The strange part is that it is non-deterministic. If the folder the md file is located in is not a trusted path I am getting in 90% of all cases the pure edit view. And in about 10% the full-screen MD preview as shown in @manav014 video pops up.

If I add the folder to the list of trusted folders then then it works similar just in 90% of all cases the vertical split view is shown with left the editor and right the preview. And in 10% of all cases only the full-screen preview is shown.

Version: 1.91.1 (system setup)
Commit: f1e16e1e6214d7c44d078b1f0607b2388f29d729
Date: 2024-07-09T22:06:49.809Z
Electron: 29.4.0
ElectronBuildId: 9728852
Chromium: 122.0.6261.156
Node.js: 20.9.0
V8: 12.2.281.27-electron.0
OS: Windows_NT x64 10.0.22631