Skip to content

Commit

Permalink
feat: add command to open existed markdown as markmap
Browse files Browse the repository at this point in the history
fix #6
  • Loading branch information
gera2ld committed Feb 1, 2021
1 parent 0ddb04d commit 453b512
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 11 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand All @@ -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) {}

Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 453b512

Please sign in to comment.