Search code examples
markdownvisual-studio-codevscode-keybinding

How to detect if an editor is a markdown preview?


Command markdown.showSource shows the source code of a markdown preview, how to write the When condition so that markdown.showSource only triggers when the active editor is indeed a markdown preview?


Solution

  • "when": "markdownPreviewFocus"

    How did I find this? (With a markdown preview editor open)

    1. Toggle the Help/Developer Tools On, go to its console.

    2. Start the command Developer: Inspect Context Keys

    I just clicked anywhere in vscode. In the developer tools console, you will get a long list of active context keys. I searched for preview and there were a few but this one looked really promising and it worked!