Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vscode): navigating focused slides #1933

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading