From 5c1072d9e6896bca5c0ecca1ad18dc7e1dbf9c7e Mon Sep 17 00:00:00 2001 From: cweijan Date: Mon, 15 Jul 2024 22:52:46 +0800 Subject: [PATCH] Bind markdown switch button shortcut --- package.json | 6 ++++++ src/service/markdownService.ts | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) 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); }