Skip to content

Commit 3cc66cf

Browse files
committed
Open note on HackMD from current editor
1 parent c35ae46 commit 3cc66cf

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"onView:mdTreeItems",
1717
"onCommand:HackMD.login",
1818
"onCommand:HackMD.logout",
19-
"onCommand:HackMD.createActiveEditorContentToHackMD"
19+
"onCommand:HackMD.createActiveEditorContentToHackMD",
20+
"onCommand:HacKMD.openNoteOnHackMD"
2021
],
2122
"license": "MIT",
2223
"homepage": "https://github.com/hackmdio/vscode-hackmd/blob/master/README.md",
@@ -116,6 +117,10 @@
116117
{
117118
"command": "HackMD.createActiveEditorContentToHackMD",
118119
"title": "HackMD: Create note from editor"
120+
},
121+
{
122+
"command": "HacKMD.openNoteOnHackMD",
123+
"title": "HacKMD: Open note on HackMD"
119124
}
120125
],
121126
"menus": {

src/commands/note.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,14 @@ export async function registerNoteCommands(context: vscode.ExtensionContext) {
1818
vscode.env.openExternal(vscode.Uri.parse(noteUrl));
1919
}
2020
}));
21+
22+
context.subscriptions.push(vscode.commands.registerCommand('HacKMD.openNoteOnHackMD', () => {
23+
const noteId = vscode.window.activeTextEditor.document.uri.fragment;
24+
if (!noteId) {
25+
vscode.window.showInformationMessage('Please open an editor first');
26+
}
27+
const serverUrl = vscode.workspace.getConfiguration('Hackmd').get('serverURL') as string;
28+
const noteUrl = `${serverUrl}/${noteId}`;
29+
vscode.env.openExternal(vscode.Uri.parse(noteUrl));
30+
}));
2131
}

src/commands/treeView.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as vscode from 'vscode';
22
import { HackMDTreeViewProvider } from './../tree/index';
33
import { NoteTreeNode } from './../tree/nodes';
44
import { MdTextDocumentContentProvider } from './../mdTextDocument';
5-
import { refreshHistoryList, refreshLoginStatus, refreshLoginCredential, getLoginCredential } from './../utils';
5+
import { refreshHistoryList, refreshLoginStatus, refreshLoginCredential } from './../utils';
66
import { API, ExportType } from './../api';
77

88
export async function registerTreeViewCommands(context: vscode.ExtensionContext) {
@@ -25,8 +25,7 @@ export async function registerTreeViewCommands(context: vscode.ExtensionContext)
2525
}
2626
}));
2727

28-
context.subscriptions.push(vscode.commands.registerCommand('note.showPreview', async (node: NoteTreeNode) => {
29-
const noteNode = node;
28+
context.subscriptions.push(vscode.commands.registerCommand('note.showPreview', async (noteNode: NoteTreeNode) => {
3029
if (noteNode.label && noteNode.noteId) {
3130
const content = await API.exportString(noteNode.noteId, ExportType.MD);
3231
if (content) {
@@ -36,8 +35,7 @@ export async function registerTreeViewCommands(context: vscode.ExtensionContext)
3635
}
3736
}));
3837

39-
context.subscriptions.push(vscode.commands.registerCommand('note.showPreviewAndEditor', async (node: NoteTreeNode) => {
40-
const noteNode = node;
38+
context.subscriptions.push(vscode.commands.registerCommand('note.showPreviewAndEditor', async (noteNode: NoteTreeNode) => {
4139
if (noteNode.label && noteNode.noteId) {
4240
const content = await API.exportString(noteNode.noteId, ExportType.MD);
4341
if (content) {

0 commit comments

Comments
 (0)