Skip to content

Commit

Permalink
Allow 1-based step numbers via URI Handler
Browse files Browse the repository at this point in the history
  • Loading branch information
lostintangent authored May 29, 2021
1 parent 7ae9935 commit d41b079
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
- Automatically set the "pattern" record mode when you create a new tour, and select `None` for the git ref
- Added support for opening a `*.tour` file in the VS Code notebook editor (Insiders only)

## v0.0.56

- URI handler now allows specifying the step via 1-based numbers, as opposed to 0-based

## v0.0.55

- The URI handler now allows specifying _just_ a step number, in order to index into a repo within only a single tour
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "CodeTour",
"description": "VS Code extension that allows you to record and playback guided tours of codebases, directly within the editor",
"publisher": "vsls-contrib",
"version": "0.0.55",
"version": "0.0.56",
"author": {
"name": "Microsoft Corporation"
},
Expand Down
34 changes: 11 additions & 23 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,19 @@ function startTour(params: URLSearchParams) {
let tourPath = params.get("tour");
const step = params.get("step");

console.log("CT Tour: ", tourPath);
console.log("CT Step: ", step);

let stepNumber;
if (step) {
stepNumber = Number(step);
// Allow the step number to be
// provided as 1-based vs. 0-based
stepNumber = Number(step) - 1;
}

if (tourPath) {
if (!tourPath.endsWith(".tour")) {
tourPath = `${tourPath}.tour`;
}

console.log("CT Tour Path: ", tourPath);

console.log("CT Tours: ", store.tours);

const tour = store.tours.find(tour => tour.id.endsWith(tourPath as string));

console.log("CT Tour: ", tour);

if (tour) {
startCodeTour(tour, stepNumber);
}
Expand All @@ -68,20 +60,16 @@ class URIHandler implements vscode.UriHandler {
this._didStartDefaultTour = true;
await discoverTours();

let query = uri.query;
if (uri.path === "/startDefaultTour") {
if (uri.query) {
console.log("CT Query: ", uri.query);
try {
const origin = vscode.Uri.parse(uri.query);
if (origin.query) {
const params = new URLSearchParams(origin.query);
startTour(params);
}
} catch {}
}
} else if (uri.path === "/starTour") {
const params = new URLSearchParams(uri.query);
query = vscode.Uri.parse(uri.query).query;
}

if (query) {
const params = new URLSearchParams(query);
startTour(params);
} else {
startDefaultTour();
}
}
}
Expand Down

0 comments on commit d41b079

Please sign in to comment.