Skip to content

Commit

Permalink
🔀 Fix for togglePreviewToSide (#780)
Browse files Browse the repository at this point in the history
Changes togglePreviewToSide to closePreviewToSide. Opening preview to
side is handled by VScode. As long as they have the same key binding, it
will behave like toggle.

Cheking for `window.activeTextEditor` is not working becase acording to
API documentation it returns:

> "The currently active editor or undefined. The active editor is the
one that currently has focus or, when none has focus, the one that
has changed input most recently."

Since "one that has changed input most recently" will always be text
editor in the current window, when preview opened to the side,
`activeTextEditor` will almost never be undefined.

When markdown preview has focus it sets the context
`markdownPreviewFocus`. Since there no way of getting contexts from the
extension code like described here
microsoft/vscode#46445 (comment)
I think it's better to change toggle to close and check for
`markdownPreviewFocus` from key bindings.
  • Loading branch information
antontkv authored Aug 12, 2020
1 parent 062cf59 commit 20316d5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@
"when": "!terminalFocus"
},
{
"command": "markdown.extension.togglePreviewToSide",
"command": "markdown.extension.closePreviewToSide",
"key": "ctrl+k v",
"mac": "cmd+k v",
"when": "!terminalFocus"
"when": "markdownPreviewFocus"
},
{
"command": "markdown.extension.editing.paste",
Expand Down
9 changes: 2 additions & 7 deletions src/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,8 @@ export function activate(context: ExtensionContext) {
commands.executeCommand('markdown.showPreview');
}
}),
commands.registerCommand('markdown.extension.togglePreviewToSide', () => {
let editor = window.activeTextEditor;
if (!editor) {
commands.executeCommand('workbench.action.closeActiveEditor');
} else if (editor.document.languageId === 'markdown') {
commands.executeCommand('markdown.showPreviewToSide');
}
commands.registerCommand('markdown.extension.closePreviewToSide', () => {
commands.executeCommand('workbench.action.closeActiveEditor');
})
);
}
Expand Down

0 comments on commit 20316d5

Please sign in to comment.