Skip to content

Commit

Permalink
Added snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
estruyf committed Dec 9, 2024
1 parent 32cca5a commit 93f9167
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
.vscode/**
.vscode-test/**
src/**
snippets
.gitignore
.yarnrc
vsc-extension-quickstart.md
**/tsconfig.json
**/tsup.config.ts
**/.eslintrc.json
**/*.map
**/*.ts
**/*.ts
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [0.0.36] - 2025-12-09

- [#2](https://github.com/estruyf/vscode-demo-time/issues/2): Added the ability to have a `variables.json` file to store variables/constants that can be used in the demo steps
- Added example snippets to the project

## [0.0.35] - 2025-12-09

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,8 @@ To reset the settings, you can use the following steps:
</tr>
</table>

> You can find examples of snippets in the [snippets](https://github.com/estruyf/vscode-demo-time/tree/dev/snippets/README.md) folder.
#### Snippet example

In the demo file, you can reference a snippet file. The snippet file can contain multiple steps which can be reused in multiple demos.
Expand Down
61 changes: 61 additions & 0 deletions snippets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Snippets

This directory contains code snippets that can be used in your projects. Each snippet is a self-contained piece of code that can be copied and pasted into your project.

## Prerequisites

Create a `snippets` folder in the `.demo` directory of your project. This is where you will store your snippets.

> [!NOTE]
> You can change name of the snippets folder, but you will need to update the `contentPath` in the snippet action.
## Insert and highlight code

The [insert_and_highlight.json](./insert_and_highlight.json) snippet contains a couple of steps to insert code and highlight specific lines after inserting the content.

You can configure the snippet action as follows:

```json
{
"action": "snippet",
"contentPath": "./snippets/insert_and_highlight.json",
"args": {
"MAIN_FILE": "<relative path from workspace to the file to update>",
"CONTENT_PATH": "<relative path in .demo folder to the file with the contents to insert>",
"CONTENT_POSITION": "<line number>",
"HIGHLIGHT_POSITION": "<line number>:<line number>"
}
}
```

## Show slide

The [show_slide.json](./show_slide.json) snippet contains a step to show a slide within Visual Studio Code.

You can configure the snippet action as follows:

```json
{
"action": "snippet",
"contentPath": "./snippets/show_slide.json",
"args": {
"SLIDES_URL": "<URL to the slide>"
}
}
```

> [!NOTE]
> I'm making use of [Slidev](https://sli.dev/) to create slides and as it generates a site, I can use the URL to show the slide in Visual Studio Code.
## Reset view after slide

The [reset_view_after_slide.json](./reset_view_after_slide.json) snippet contains the steps to reset the view after showing a slide.

You can configure the snippet action as follows:

```json
{
"action": "snippet",
"contentPath": "./snippets/reset_view_after_slide.json"
}
```
21 changes: 21 additions & 0 deletions snippets/insert_and_highlight.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[
{
"action": "unselect",
"path": "{MAIN_FILE}"
},
{
"action": "insert",
"path": "{MAIN_FILE}",
"contentPath": "{CONTENT_PATH}",
"position": "{CONTENT_POSITION}"
},
{
"action": "waitForTimeout",
"timeout": 500
},
{
"action": "highlight",
"path": "{MAIN_FILE}",
"position": "{HIGHLIGHT_POSITION}"
}
]
16 changes: 16 additions & 0 deletions snippets/reset_view_after_slide.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[{
"action": "setSetting",
"args": {
"setting": "workbench.statusBar.visible",
"value": null
}
}, {
"action": "setSetting",
"args": {
"setting": "workbench.activityBar.location",
"value": null
}
}, {
"action": "executeVSCodeCommand",
"command": "workbench.action.toggleSidebarVisibility"
}]
23 changes: 23 additions & 0 deletions snippets/show_slide.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[{
"action": "executeVSCodeCommand",
"command": "workbench.action.closeSidebar"
}, {
"action": "executeVSCodeCommand",
"command": "workbench.action.closePanel"
}, {
"action": "setSetting",
"args": {
"setting": "workbench.statusBar.visible",
"value": false
}
}, {
"action": "setSetting",
"args": {
"setting": "workbench.activityBar.location",
"value": "hidden"
}
}, {
"action": "executeVSCodeCommand",
"command": "simpleBrowser.show",
"args": "{SLIDES_URL}"
}]
14 changes: 0 additions & 14 deletions todo.md

This file was deleted.

0 comments on commit 93f9167

Please sign in to comment.