diff --git a/package.json b/package.json index 70e94a3..764bd53 100755 --- a/package.json +++ b/package.json @@ -222,6 +222,12 @@ "command": "office.html.preview", "key": "ctrl+shift+v", "when": "editorTextFocus && editorLangId == html" + }, + { + "command": "office.markdown.switch", + "key": "ctrl+alt+e", + "mac": "ctrl+cmd+e", + "when": "editorTextFocus && editorLangId == markdown" } ], "menus": { diff --git a/src/service/markdownService.ts b/src/service/markdownService.ts index eca1392..319d88a 100644 --- a/src/service/markdownService.ts +++ b/src/service/markdownService.ts @@ -206,7 +206,9 @@ export class MarkdownService { } public switchEditor(uri: vscode.Uri) { - const type = vscode.window.activeTextEditor ? 'cweijan.markdownViewer' : 'default'; + const editor = vscode.window.activeTextEditor; + if (!uri) uri = editor?.document.uri; + const type = editor ? 'cweijan.markdownViewer' : 'default'; vscode.commands.executeCommand('vscode.openWith', uri, type); }