diff --git a/packages/vscode/src/composables/useFocusedSlideNo.ts b/packages/vscode/src/composables/useFocusedSlideNo.ts index e61c4fe035..5071404850 100644 --- a/packages/vscode/src/composables/useFocusedSlideNo.ts +++ b/packages/vscode/src/composables/useFocusedSlideNo.ts @@ -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' @@ -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) diff --git a/packages/vscode/src/views/slidesTree.ts b/packages/vscode/src/views/slidesTree.ts index b846678941..e11f5f8de2 100644 --- a/packages/vscode/src/views/slidesTree.ts +++ b/packages/vscode/src/views/slidesTree.ts @@ -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) {