1- import * as vscode from 'vscode'
1+ import * as vscode from 'vscode' ;
22import { Store } from '../store' ;
33import * as apiClient from '@hackmd/api' ;
4- import { HackMDTreeViewProvider } from './../tree/index'
4+ import { HackMDTreeViewProvider } from './../tree/index' ;
5+ import { NoteTreeNode } from './../tree/nodes' ;
56import { MdTextDocumentContentProvider } from './../mdTextDocument' ;
67const API = new apiClient . default ( ) ;
78
@@ -20,5 +21,30 @@ export async function registerTreeViewCommands(context: vscode.ExtensionContext,
2021 }
2122 }
2223 } ) ) ;
24+
25+ context . subscriptions . push ( vscode . commands . registerCommand ( 'note.showPreview' , async ( node : NoteTreeNode ) => {
26+ const noteNode = node ;
27+ if ( noteNode . label && noteNode . noteId ) {
28+ const content = await API . exportString ( noteNode . noteId , apiClient . ExportType . MD ) ;
29+ if ( content ) {
30+ const uri = vscode . Uri . parse ( `hackmd:${ noteNode . label } .md#${ noteNode . noteId } ` ) ;
31+ vscode . commands . executeCommand ( 'markdown.showPreview' , uri ) ;
32+ }
33+ }
34+ } ) ) ;
35+
36+ context . subscriptions . push ( vscode . commands . registerCommand ( 'note.showPreviewAndEditor' , async ( node : NoteTreeNode ) => {
37+ const noteNode = node ;
38+ if ( noteNode . label && noteNode . noteId ) {
39+ const content = await API . exportString ( noteNode . noteId , apiClient . ExportType . MD ) ;
40+ if ( content ) {
41+ const uri = vscode . Uri . parse ( `hackmd:${ noteNode . label } .md#${ noteNode . noteId } ` ) ;
42+ const doc = await vscode . workspace . openTextDocument ( uri ) ;
43+ await vscode . window . showTextDocument ( doc , { preview : false } ) ;
44+ vscode . commands . executeCommand ( 'markdown.showPreviewToSide' , uri ) ;
45+ }
46+ }
47+ } ) ) ;
48+
2349 context . subscriptions . push ( vscode . workspace . registerTextDocumentContentProvider ( 'hackmd' , new MdTextDocumentContentProvider ( ) ) ) ;
2450}
0 commit comments