@@ -11,7 +11,7 @@ const DEFAULT_SLIDE_NAME = 'New Slide'
1111export default class PresentationCanvasExtension extends CanvasExtension {
1212 savedViewport : any = null
1313 isPresentationMode : boolean = false
14- visitedNodes : any [ ] = [ ]
14+ visitedNodeIds : string [ ] = [ ]
1515 fullscreenModalObserver : MutationObserver | null = null
1616
1717 isEnabled ( ) { return 'presentationFeatureEnabled' as const }
@@ -276,14 +276,14 @@ export default class PresentationCanvasExtension extends CanvasExtension {
276276
277277 private async startPresentation ( canvas : Canvas , tryContinue : boolean = false ) {
278278 // Only reset visited nodes if we are not trying to continue
279- if ( ! tryContinue || this . visitedNodes . length === 0 ) {
279+ if ( ! tryContinue || this . visitedNodeIds . length === 0 ) {
280280 const startNode = this . getStartNode ( canvas )
281281 if ( ! startNode ) {
282282 new Notice ( 'No start node found. Please mark a node as a start node trough the popup menu.' )
283283 return
284284 }
285285
286- this . visitedNodes = [ startNode ]
286+ this . visitedNodeIds = [ startNode . getData ( ) . id ]
287287 }
288288
289289 // Save current viewport
@@ -340,7 +340,13 @@ export default class PresentationCanvasExtension extends CanvasExtension {
340340 await sleep ( 500 )
341341
342342 // Zoom to first node
343- this . animateNodeTransition ( canvas , undefined , this . visitedNodes . last ( ) )
343+ const startNodeId = this . visitedNodeIds . first ( )
344+ if ( ! startNodeId ) return
345+
346+ const startNode = canvas . nodes . get ( startNodeId )
347+ if ( ! startNode ) return
348+
349+ this . animateNodeTransition ( canvas , undefined , startNode )
344350 }
345351
346352 private endPresentation ( canvas : Canvas ) {
@@ -365,10 +371,13 @@ export default class PresentationCanvasExtension extends CanvasExtension {
365371 }
366372
367373 private nextNode ( canvas : Canvas ) {
368- const fromNode = this . visitedNodes . last ( )
374+ const fromNodeId = this . visitedNodeIds . last ( )
375+ if ( ! fromNodeId ) return
376+
377+ const fromNode = canvas . nodes . get ( fromNodeId )
369378 if ( ! fromNode ) return
370379
371- const outgoingEdges = canvas . getEdgesForNode ( fromNode ) . filter ( ( edge : CanvasEdge ) => edge . from . node === fromNode )
380+ const outgoingEdges = canvas . getEdgesForNode ( fromNode ) . filter ( ( edge : CanvasEdge ) => edge . from . node . getData ( ) . id === fromNodeId )
372381 let toNode = outgoingEdges . first ( ) ?. to . node
373382
374383 // If there are multiple outgoing edges, we need to look at the edge label
@@ -383,16 +392,16 @@ export default class PresentationCanvasExtension extends CanvasExtension {
383392 } )
384393
385394 // Find which edges already have been traversed
386- const traversedEdgesCount = this . visitedNodes
387- . filter ( ( visitedNode : CanvasNode ) => visitedNode == fromNode ) . length - 1
395+ const traversedEdgesCount = this . visitedNodeIds
396+ . filter ( ( visitedNodeId : string ) => visitedNodeId === fromNodeId ) . length - 1
388397
389398 // Select next edge
390399 const nextEdge = sortedEdges [ traversedEdgesCount ]
391400 toNode = nextEdge . to . node
392401 }
393402
394403 if ( toNode ) {
395- this . visitedNodes . push ( toNode )
404+ this . visitedNodeIds . push ( toNode . getData ( ) . id )
396405 this . animateNodeTransition ( canvas , fromNode , toNode )
397406 } else {
398407 // No more nodes left, animate to same node
@@ -401,15 +410,22 @@ export default class PresentationCanvasExtension extends CanvasExtension {
401410 }
402411
403412 private previousNode ( canvas : Canvas ) {
404- const fromNode = this . visitedNodes . pop ( )
413+ const fromNodeId = this . visitedNodeIds . pop ( )
414+ if ( ! fromNodeId ) return
415+
416+ const fromNode = canvas . nodes . get ( fromNodeId )
405417 if ( ! fromNode ) return
406418
407- let toNode = this . visitedNodes . last ( )
419+ const toNodeId = this . visitedNodeIds . last ( )
420+ if ( ! toNodeId ) return
421+
422+ let toNode = canvas . nodes . get ( toNodeId )
423+ if ( ! toNode ) return
408424
409425 // Fall back to same node if there are no more nodes before
410426 if ( ! toNode ) {
411427 toNode = fromNode
412- this . visitedNodes . push ( fromNode )
428+ this . visitedNodeIds . push ( fromNodeId )
413429 }
414430
415431 this . animateNodeTransition ( canvas , fromNode , toNode )
0 commit comments