Skip to content

Commit 0443c1e

Browse files
committed
Add new note command
1 parent 174dd20 commit 0443c1e

4 files changed

Lines changed: 35 additions & 5 deletions

File tree

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
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",
@@ -87,6 +88,10 @@
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": {

src/commands/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import * as vscode from 'vscode';
22
import { registerUserCommands } from './user'
33
import { registerTreeViewCommands } from './treeView'
4+
import { registerNoteCommands } from './note';
45
import { Store } from '../store';
56

67
export function registerCommand(context: vscode.ExtensionContext, store: Store) {
78
registerUserCommands(context, store);
89
registerTreeViewCommands(context, store);
10+
registerNoteCommands(context);
911
}

src/commands/note.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
}

src/mdTextDocument.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)