File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515 "activationEvents" : [
1616 " onView:mdTreeItems" ,
1717 " onCommand:HackMD.login" ,
18- " onCommand::HackMD.logout"
18+ " onCommand:HackMD.logout" ,
19+ " onCommand:note.newNote"
1920 ],
2021 "license" : " MIT" ,
2122 "homepage" : " https://github.com/hackmdio/vscode-hackmd/blob/master/README.md" ,
8788 "command" : " note.showPreviewAndEditor" ,
8889 "title" : " Show preview to side" ,
8990 "icon" : " src/icon/education.svg"
91+ },
92+ {
93+ "command" : " note.newNote" ,
94+ "title" : " New note"
9095 }
9196 ],
9297 "menus" : {
Original file line number Diff line number Diff line change 11import * as vscode from 'vscode' ;
22import { registerUserCommands } from './user'
33import { registerTreeViewCommands } from './treeView'
4+ import { registerNoteCommands } from './note' ;
45import { Store } from '../store' ;
56
67export function registerCommand ( context : vscode . ExtensionContext , store : Store ) {
78 registerUserCommands ( context , store ) ;
89 registerTreeViewCommands ( context , store ) ;
10+ registerNoteCommands ( context ) ;
911}
Original file line number Diff line number Diff line change 1+ import * as vscode from 'vscode' ;
2+ import * as apiClient from '@hackmd/api' ;
3+ import { checkLogin } from './../tree/index' ;
4+ const API = new apiClient . default ( ) ;
5+
6+ export async function registerNoteCommands ( context : vscode . ExtensionContext ) {
7+ context . subscriptions . push ( vscode . commands . registerCommand ( 'note.newNote' , async ( ) => {
8+ if ( ! ( await checkLogin ( ) ) ) {
9+ vscode . window . showInformationMessage ( 'Please login first.' ) ;
10+ return ;
11+ }
12+ const mdText = await vscode . window . showInputBox ( {
13+ ignoreFocusOut : true ,
14+ password : false ,
15+ placeHolder : 'MarkDown content' ,
16+ prompt : 'Please write down your note text' ,
17+ } ) ;
18+
19+ const noteUrl = await API . newNote ( mdText ) ;
20+ const clicked = await vscode . window . showInformationMessage ( 'New note Established!' , ...[ 'Copy URL to clip board' , 'Open in browser' ] ) ;
21+ if ( clicked === 'Copy URL to clip board' ) {
22+ vscode . env . clipboard . writeText ( noteUrl ) ;
23+ } else if ( clicked === 'Open in browser' ) {
24+ vscode . env . openExternal ( vscode . Uri . parse ( noteUrl ) ) ;
25+ }
26+ } ) ) ;
27+ }
Original file line number Diff line number Diff line change @@ -6,10 +6,6 @@ export class MdTextDocumentContentProvider implements vscode.TextDocumentContent
66 async provideTextDocumentContent ( uri : vscode . Uri ) : Promise < string > {
77 const noteId = uri . fragment ;
88 const content = await API . exportString ( noteId , apiClient . ExportType . MD ) ;
9- // vscode.commands.executeCommand('markdown.showSource', content);
10- // vscode.commands.executeCommand('markdown.showPreviewToSide', content);
11-
12- // vscode.commands.executeCommand('markdown.showSource', content);
139 return content ;
1410 }
1511}
You can’t perform that action at this time.
0 commit comments