Skip to content

Commit

Permalink
feat: improved open in editor
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jun 27, 2021
1 parent 8e81529 commit 20f0b09
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
15 changes: 3 additions & 12 deletions packages/client/internals/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useEventListener, throttledWatch } from '@vueuse/core'
import { computed, watch, ref, onMounted } from 'vue'
import { activeElement, showEditor, editorWidth, isInputting } from '../state'
import { useCodeMirror } from '../setup/codemirror'
import { currentRoute, currentSlideId } from '../logic/nav'
import { currentSlideId, openInEditor } from '../logic/nav'
import { useDynamicSlideInfo } from '../logic/note'
const tab = ref<'content' | 'note'>('content')
Expand Down Expand Up @@ -114,13 +114,6 @@ useEventListener('resize', () => {
updateWidth(editorWidth.value)
})
const editorLink = computed(() => {
const slide = currentRoute.value?.meta?.slide
return (slide?.filepath)
? `vscode://file/${slide.filepath}:${slide.start}`
: undefined
})
throttledWatch(
[content, note],
() => {
Expand Down Expand Up @@ -155,10 +148,8 @@ throttledWatch(
{{ tab === 'content' ? 'Slide' : 'Note' }}
</span>
<div class="flex-auto"></div>
<button class="icon-btn">
<a :href="editorLink" target="_blank">
<carbon:launch />
</a>
<button class="icon-btn" @click="openInEditor()">
<carbon:launch />
</button>
<button class="icon-btn" @click="close">
<carbon:close />
Expand Down
11 changes: 11 additions & 0 deletions packages/client/logic/nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,14 @@ export async function downloadPDF() {
`${configs.title}.pdf`,
)
}

export async function openInEditor(url?: string) {
if (url == null) {
const slide = currentRoute.value?.meta?.slide
if (!slide?.filepath)
return false
url = `${slide.filepath}:${slide.start}`
}
await fetch(`/__open-in-editor?file=${encodeURIComponent(url)}`)
return true
}
18 changes: 12 additions & 6 deletions packages/create-app/template/slides.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@ info: |
Presentation slides for developers

<div class="pt-12">
<span @click="$slidev.nav.next" class="px-2 p-1 rounded cursor-pointer" hover="bg-white bg-opacity-10">
<span @click="$slidev.nav.next" class="px-2 py-1 rounded cursor-pointer" hover="bg-white bg-opacity-10">
Press Space for next page <carbon:arrow-right class="inline"/>
</span>
</div>

<a href="https://github.com/slidevjs/slidev" target="_blank" alt="GitHub"
class="abs-br m-6 text-xl icon-btn opacity-50 !border-none !hover:text-white">
<carbon-logo-github />
</a>
<div class="abs-br m-6 flex gap-2">
<button @click="$slidev.nav.openInEditor()" title="Open in Editor" class="text-xl icon-btn opacity-50 !border-none !hover:text-white">
<carbon:edit />
</button>
<a href="https://github.com/slidevjs/slidev" target="_blank" alt="GitHub"
class="text-xl icon-btn opacity-50 !border-none !hover:text-white">
<carbon-logo-github />
</a>
</div>


<!--
The last comment block of each slide will be treated as slide notes. It will be visible and editable in Presenter Mode along with the slide. [Read more in the docs](https://sli.dev/guide/syntax.html#notes)
Expand Down Expand Up @@ -335,4 +341,4 @@ class: text-center

# Learn More

[Documentations](https://sli.dev) / [GitHub](https://github.com/slidevjs/slidev) / [Showcases](https://sli.dev/showcases.html)
[Documentations](https://sli.dev) · [GitHub](https://github.com/slidevjs/slidev) · [Showcases](https://sli.dev/showcases.html)

0 comments on commit 20f0b09

Please sign in to comment.