Skip to content

Commit 127da44

Browse files
authored
feat: add uri handler used to open a existing post (#46)
1 parent 8181ed6 commit 127da44

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/extension.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
observeConfigurationChange,
1010
observeWorkspaceFolderAndFileChange as observeWorkspaceFolderChange,
1111
} from './services/check-workspace';
12+
import { EditPostUriHandler } from './services/edit-post-uri-handler';
1213

1314
// this method is called when your extension is activated
1415
// your extension is activated the very first time the command is executed
@@ -21,6 +22,7 @@ export function activate(context: vscode.ExtensionContext) {
2122
registerTreeViews();
2223
observeConfigurationChange();
2324
observeWorkspaceFolderChange();
25+
vscode.window.registerUriHandler(new EditPostUriHandler());
2426
}
2527

2628
// this method is called when your extension is deactivated

src/services/edit-post-uri-handler.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { ProviderResult, Uri, UriHandler } from 'vscode';
2+
import { openPostInVscode } from '../commands/posts-list/open-post-in-vscode';
3+
4+
export class EditPostUriHandler implements UriHandler {
5+
handleUri(uri: Uri): ProviderResult<void> {
6+
const { path } = uri;
7+
const splits = path.split('/');
8+
if (splits.length >= 3 && splits[1] === 'edit-post') {
9+
const postId = parseInt(splits[2]);
10+
if (postId > 0) {
11+
openPostInVscode(postId).then(undefined, () => void 0);
12+
}
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)