visual-studio-codevscode-keybinding

Switch to, and from, Preview, with 1 keyboard shortcut?


I tried using textInputFocus && !inputFocus && editorLangId == 'markdown' and textInputFocus && editorReadonly && editorLangId == 'markdown' in When Expression for markdown.showSource, with relevant respective versions for markdown.showPreview .

But the shortcut still doesn't work when the Preview has Focus .


Solution

  • If you look at the markdown.showSource in the Keybindings Shortcuts you will see it has no context/when clause. It must just find the matching resource and go to it.

    Also when a preview is active, you will see that the language ID in the bottom right corner disappears, so editorLangId == markdown will presumably always fail.

    If you want a when clause to prevent keybinding conflicts, try:

      {
        "key": "alt+e",
        "command": "markdown.showSource",
        "when": "markdownPreviewFocus"
      }
    

    Learn about the Developer: Inspect Context Keys command, see inspect context keys utility. That is how I found the markdownPreviewFocus clause.