Skip to content

Commit

Permalink
fix(vscode): navigating focused slides (#1933)
Browse files Browse the repository at this point in the history
  • Loading branch information
KermanX authored Nov 4, 2024
1 parent 3be1191 commit ba32ba1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
11 changes: 5 additions & 6 deletions packages/vscode/src/composables/useFocusedSlideNo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createSingletonComposable, ref, useActiveTextEditor, useTextEditorSelection, watchEffect } from 'reactive-vscode'
import { createSingletonComposable, ref, useActiveTextEditor, useTextEditorSelection, watch } from 'reactive-vscode'
import { TextEditorSelectionChangeKind } from 'vscode'
import { activeSlidevData } from '../projects'
import { getFirstDisplayedChild } from '../utils/getFirstDisplayedChild'
Expand All @@ -10,12 +10,11 @@ export const useFocusedSlideNo = createSingletonComposable(() => {

const slideNo = ref(1)

watchEffect(() => {
const data = activeSlidevData.value
const projectInfo = getProjectFromDoc(editor.value?.document)
if (!data || !projectInfo || !editor.value)
watch([activeSlidevData, editor, selection], ([data, editor, selection]) => {
const projectInfo = getProjectFromDoc(editor?.document)
if (!data || !projectInfo || !editor)
return
const line = selection.value.active.line + 1
const line = selection.active.line + 1
const slide = projectInfo.md.slides.find(s => s.start <= line && line <= s.end)
if (slide) {
const source = getFirstDisplayedChild(slide)
Expand Down
10 changes: 5 additions & 5 deletions packages/vscode/src/views/slidesTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,16 @@ export const useSlidesTree = createSingletonComposable(() => {
const visible = useViewVisibility(treeView)
const { previewNavState } = usePreviewWebview()
watch(
() => [visible.value, previewNavState.no, activeSlidevData.value, slidesTreeData.value] as const,
([visible, no, data, tree]) => {
if (!visible)
() => previewNavState.no,
(no) => {
if (!visible.value)
return
const slide = data?.slides[no - 1]
const slide = activeSlidevData.value?.slides[no - 1]
if (!slide || !previewSync.value)
return
const path = (slide.importChain ?? []).concat(slide.source)
const source = path.shift()
let node = tree?.find(e => e.slide === source)
let node = slidesTreeData.value?.find(e => e.slide === source)
while (true) {
const source = path.shift()
if (!source) {
Expand Down

0 comments on commit ba32ba1

Please sign in to comment.