@@ -2910,40 +2910,35 @@ export class TrainrunSectionsView {
29102910 textElement : TrainrunSectionText ,
29112911 editorView : EditorView ,
29122912 ) {
2913- const trainrunSection = viewObject . trainrunSections [ 0 ] ;
2914-
29152913 switch ( textElement ) {
29162914 case TrainrunSectionText . SourceDeparture :
29172915 case TrainrunSectionText . SourceArrival :
29182916 // For source times, use the original section times (should be from non-collapsed node)
29192917 return TrainrunSectionsView . getTrainrunSectionValueToShow (
2920- trainrunSection ,
2918+ viewObject . trainrunSections [ 0 ] ,
29212919 textElement ,
29222920 editorView ,
29232921 ) ;
29242922
29252923 case TrainrunSectionText . TargetDeparture :
29262924 case TrainrunSectionText . TargetArrival : {
29272925 // For collapsed chains, use the actual time from the last section in the chain
2928- const chainSections = this . getAllSectionsInCollapsedChain ( trainrunSection ) ;
2929- const lastSection = chainSections [ chainSections . length - 1 ] ;
2930-
29312926 // Use the actual time from the last section (which already includes all stops and travel times)
29322927 return TrainrunSectionsView . getTrainrunSectionValueToShow (
2933- lastSection ,
2928+ viewObject . trainrunSections . at ( - 1 ) ! ,
29342929 textElement ,
29352930 editorView ,
29362931 ) ;
29372932 }
29382933
29392934 case TrainrunSectionText . TrainrunSectionTravelTime : {
29402935 // For collapsed chains, calculate total time including stops at collapsed nodes
2941- const chainSections = this . getAllSectionsInCollapsedChain ( trainrunSection ) ;
2942- const lastSection = chainSections [ chainSections . length - 1 ] ;
2936+ const firstSection = viewObject . trainrunSections [ 0 ] ;
2937+ const lastSection = viewObject . trainrunSections . at ( - 1 ) ! ;
29432938
29442939 // Calculate total time: arrival time at end - departure time at start
29452940 const startTime = TrainrunSectionsView . getTime (
2946- trainrunSection ,
2941+ firstSection ,
29472942 TrainrunSectionText . SourceDeparture ,
29482943 ) ;
29492944 const endTime = TrainrunSectionsView . getTime (
@@ -2959,51 +2954,9 @@ export class TrainrunSectionsView {
29592954
29602955 case TrainrunSectionText . TrainrunSectionName :
29612956 // For name, use the original trainrun name
2962- return TrainrunSectionsView . extractTrainrunName ( trainrunSection ) ;
2957+ return TrainrunSectionsView . extractTrainrunName ( viewObject . trainrunSections [ 0 ] ) ;
29632958 }
29642959
29652960 return undefined ;
29662961 }
2967-
2968- /**
2969- * Get all sections that are part of the same collapsed chain
2970- */
2971- getAllSectionsInCollapsedChain ( currentSection : TrainrunSection ) : TrainrunSection [ ] {
2972- const sections : TrainrunSection [ ] = [ ] ;
2973- let startSection = currentSection ;
2974-
2975- // Walk backwards to find start of chain
2976- while ( startSection . getSourceNode ( ) . getIsCollapsed ( ) ) {
2977- const prevSections = this . getConnectedTrainrunSections (
2978- startSection . getSourceNode ( ) ,
2979- currentSection . getTrainrunId ( ) ,
2980- ) . filter ( ( ts ) => ts . getId ( ) !== startSection . getId ( ) ) ;
2981-
2982- if ( prevSections . length === 1 ) {
2983- startSection = prevSections [ 0 ] ;
2984- } else {
2985- break ;
2986- }
2987- }
2988-
2989- // Walk forwards to find end of chain and collect all sections
2990- let currentSectionInChain = startSection ;
2991- sections . push ( currentSectionInChain ) ;
2992-
2993- while ( currentSectionInChain . getTargetNode ( ) . getIsCollapsed ( ) ) {
2994- const nextSections = this . getConnectedTrainrunSections (
2995- currentSectionInChain . getTargetNode ( ) ,
2996- currentSection . getTrainrunId ( ) ,
2997- ) . filter ( ( ts ) => ts . getId ( ) !== currentSectionInChain . getId ( ) ) ;
2998-
2999- if ( nextSections . length === 1 ) {
3000- currentSectionInChain = nextSections [ 0 ] ;
3001- sections . push ( currentSectionInChain ) ;
3002- } else {
3003- break ;
3004- }
3005- }
3006-
3007- return sections ;
3008- }
30092962}
0 commit comments