Skip to content

Commit

Permalink
fix(vscode): project tree commands (#2025)
Browse files Browse the repository at this point in the history
  • Loading branch information
KermanX authored Jan 30, 2025
1 parent ad1034d commit 0c25256
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 45 deletions.
20 changes: 4 additions & 16 deletions packages/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
"command": "slidev.stop-dev",
"category": "Slidev",
"title": "Stop the dev server",
"icon": "$(debug-stop)"
"icon": "$(stop-circle)"
},
{
"command": "slidev.open-in-browser",
Expand Down Expand Up @@ -239,11 +239,6 @@
"title": "Unsync preview window with editor cursor",
"icon": "$(lock)",
"enablement": "slidev:preview:sync"
},
{
"command": "slidev.remove-slide",
"category": "Slidev",
"title": "Remove this slide"
}
],
"menus": {
Expand All @@ -255,10 +250,6 @@
{
"command": "slidev.set-as-active",
"when": "false"
},
{
"command": "slidev.remove-slide",
"when": "false"
}
],
"editor/title": [
Expand Down Expand Up @@ -338,16 +329,13 @@
},
{
"command": "slidev.remove-entry",
"when": "view == slidev-projects-tree&& viewItem =~ /<project>/",
"when": "view == slidev-projects-tree && viewItem =~ /<project>/",
"group": "inline@2"
},
{
"command": "slidev.stop-dev",
"when": "view == slidev-projects-tree && viewItem =~ /<up>/"
},
{
"command": "slidev.remove-slide",
"when": "view == slidev-slides-tree"
"when": "view == slidev-projects-tree && viewItem =~ /<up>/",
"group": "inline"
}
]
},
Expand Down
26 changes: 11 additions & 15 deletions packages/vscode/src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import type { SlidevProject } from './projects'
import type { SlidesTreeNode } from './views/slidesTree'
import { relative } from 'node:path'
import { slash } from '@antfu/utils'
import { save as saveSlidevMarkdown } from '@slidev/parser/fs'
import { useCommand } from 'reactive-vscode'
import { Position, Range, Selection, TextEditorRevealType, Uri, window, workspace } from 'vscode'
import { useDevServer } from './composables/useDevServer'
Expand Down Expand Up @@ -45,19 +42,24 @@ export function useCommands() {
}
})

useCommand('slidev.remove-entry', async (project: SlidevProject) => {
const entry = project.entry
useCommand('slidev.remove-entry', async (node: any) => {
const entry = slash(node.treeItem.resourceUri.fsPath)
if (activeEntry.value === entry)
activeEntry.value = null
projects.delete(entry)
})

useCommand('slidev.set-as-active', async (project: SlidevProject) => {
activeEntry.value = project.entry
useCommand('slidev.set-as-active', async (node: any) => {
const entry = slash(node.treeItem.resourceUri.fsPath)
activeEntry.value = entry
})

useCommand('slidev.stop-dev', async (project: SlidevProject) => {
const { stop } = useDevServer(project)
useCommand('slidev.stop-dev', async (node: any) => {
const entry = node ? slash(node.treeItem.resourceUri.fsPath) : activeEntry.value
if (!entry)
return
const project = projects.get(entry)
const { stop } = useDevServer(project!)
stop()
})

Expand Down Expand Up @@ -153,10 +155,4 @@ export function useCommands() {

useCommand('slidev.enable-preview-sync', () => (previewSync.value = true))
useCommand('slidev.disable-preview-sync', () => (previewSync.value = false))

useCommand('slidev.remove-slide', async ({ slide }: SlidesTreeNode) => {
const md = activeSlidevData.value!.markdownFiles[slide.filepath]
md.slides.splice(md.slides.indexOf(slide), 1)
await saveSlidevMarkdown(md)
})
}
3 changes: 2 additions & 1 deletion packages/vscode/src/views/slidesTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const layoutIconMap = {
'image-left': 'layout-sidebar-left',
'image-right': 'layout-sidebar-right',
'image': 'file-media', // TODO: a better icon
'intro': 'go-to-file',
'intro': 'debug-step-into',
'outro': 'debug-step-out',
'none': 'layout-statusbar',
'quote': 'quote',
'section': 'symbol-module', // TODO: a better icon
Expand Down
20 changes: 10 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ catalog:
prettier-plugin-slidev: ^1.0.5
prompts: ^2.4.2
public-ip: ^7.0.1
reactive-vscode: 0.2.0
reactive-vscode: ^0.2.10
recordrtc: ^5.6.2
resolve-from: ^5.0.0
resolve-global: ^2.0.0
Expand Down
2 changes: 0 additions & 2 deletions taze.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@ export default defineConfig({
'typeit': 'ignore',
// `engines.vscode` must be updated when bumping `@types/vscode` version
'@types/vscode': 'ignore',
// reactive-vscode is not stable yet
'reactive-vscode': 'ignore',
},
})

0 comments on commit 0c25256

Please sign in to comment.