From 453b512e33cee90be69017dbefddb464183a2991 Mon Sep 17 00:00:00 2001 From: Gerald Date: Mon, 1 Feb 2021 13:55:53 +0800 Subject: [PATCH] feat: add command to open existed markdown as markmap fix #6 --- README.md | 7 +++++++ package.json | 7 +++++++ src/extension.ts | 12 +++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 99a82fb..a9234ba 100644 --- a/README.md +++ b/README.md @@ -11,4 +11,11 @@ This extension integrates [markmap](https://markmap.js.org/) into VSCode. ## Usage +### Open a markdown file as markmap + +- Open a markdown file, for instance `README.md`. +- Open the Command Palette (⇧⌘P) and search `Open as markmap`, press enter. + +### Open a markmap file + Create or open a file whose name ends with `.mm.md`, and enjoy. diff --git a/package.json b/package.json index c309238..2172f7f 100644 --- a/package.json +++ b/package.json @@ -19,9 +19,16 @@ "markdown" ], "activationEvents": [ + "onCommand:markmap-vscode.open", "onCustomEditor:markmap-vscode.markmap" ], "contributes": { + "commands": [ + { + "command": "markmap-vscode.open", + "title": "Open as markmap" + } + ], "customEditors": [ { "viewType": "markmap-vscode.markmap", diff --git a/src/extension.ts b/src/extension.ts index d8f660d..78c210b 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -12,9 +12,11 @@ import { window, ViewColumn, workspace, + commands, } from 'vscode'; import debounce from 'lodash.debounce'; +const PREFIX = 'markmap-vscode'; const TOOLBAR_VERSION = process.env.TOOLBAR_VERSION; const TOOLBAR_CSS = `npm/markmap-toolbar@${TOOLBAR_VERSION}/dist/style.min.css`; const TOOLBAR_JS = `npm/markmap-toolbar@${TOOLBAR_VERSION}/dist/index.umd.min.js`; @@ -28,7 +30,7 @@ document.body.append(el);`); const transformer = new Transformer(); class MarkmapEditor implements CustomTextEditorProvider { - static readonly viewType = 'markmap-vscode.markmap'; + static readonly viewType = `${PREFIX}.markmap`; constructor(public context: ExtensionContext) {} @@ -160,6 +162,14 @@ class MarkmapEditor implements CustomTextEditorProvider { } export function activate(context: ExtensionContext) { + context.subscriptions.push(commands.registerCommand(`${PREFIX}.open`, () => { + commands.executeCommand( + 'vscode.openWith', + window.activeTextEditor.document.uri, + MarkmapEditor.viewType, + ViewColumn.Beside, + ); + })); context.subscriptions.push(window.registerCustomEditorProvider( MarkmapEditor.viewType, new MarkmapEditor(context),