Skip to content

Commit 28a4a49

Browse files
committed
Add open on browser command on sidebar
1 parent 6ede7be commit 28a4a49

File tree

5 files changed

+31
-11
lines changed

5 files changed

+31
-11
lines changed

package.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@
127127
{
128128
"command": "HacKMD.openNoteOnHackMD",
129129
"title": "Open note on HackMD",
130-
"category": "HackMD"
130+
"category": "HackMD",
131+
"icon": {
132+
"light": "src/icon/light/Browser-dark.png",
133+
"dark": "src/icon/dark/Browser-light.png"
134+
}
131135
}
132136
],
133137
"menus": {
@@ -156,7 +160,17 @@
156160
{
157161
"command": "HackMD.showPreviewAndEditor",
158162
"when": "view == mdTreeItems && viewItem == file"
163+
},
164+
{
165+
"command": "HacKMD.openNoteOnHackMD",
166+
"when": "view == mdTreeItems && viewItem == file",
167+
"group": "inline"
168+
},
169+
{
170+
"command": "HacKMD.openNoteOnHackMD",
171+
"when": "view == mdTreeItems && viewItem == file"
159172
}
173+
160174
]
161175
},
162176
"viewsWelcome": [

src/commands/note.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,4 @@ 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-
}));
3121
}

src/commands/treeView.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,22 @@ export async function registerTreeViewCommands(context: vscode.ExtensionContext)
7777
}
7878
}));
7979

80+
context.subscriptions.push(vscode.commands.registerCommand('HacKMD.openNoteOnHackMD', async (noteNode: NoteTreeNode) => {
81+
let noteId = '';
82+
if (noteNode) {
83+
noteId = noteNode.noteId;
84+
} else {
85+
noteId = vscode.window.activeTextEditor.document.uri.fragment;
86+
}
87+
if (!checkNoteIdExist(noteId)) { return; }
88+
89+
const serverUrl = vscode.workspace.getConfiguration('Hackmd').get('serverURL') as string;
90+
const noteUrl = `${serverUrl}/${noteId}`;
91+
vscode.env.openExternal(vscode.Uri.parse(noteUrl));
92+
}));
93+
94+
95+
8096
context.subscriptions.push(vscode.workspace.registerTextDocumentContentProvider('hackmd', new MdTextDocumentContentProvider()));
8197
}
8298

src/icon/dark/Browser-light.png

307 Bytes
Loading

src/icon/light/Browser-dark.png

292 Bytes
Loading

0 commit comments

Comments
 (0)