@@ -181,6 +181,41 @@ export function useTranscriptionTool(options: UseTranscriptionToolOptions) {
181181 ) ;
182182 }
183183
184+ function addSegment ( index : number ) {
185+ const followingSegment = editableTranscription . value [ index ] ;
186+ if ( ! followingSegment ) return ;
187+ const newSegment = {
188+ start : Math . max (
189+ editableTranscription . value [ index - 1 ] ?. end || 0 ,
190+ ( followingSegment . start ?? 0 ) - 6 ,
191+ ) ,
192+ end : followingSegment . start ,
193+ text : "" ,
194+ isHeader : false ,
195+ id : index ,
196+ } ;
197+ editableTranscription . value . splice ( index , 0 , newSegment ) ;
198+ transcription . value ?. splice ( index , 0 , structuredClone ( toRaw ( newSegment ) ) ) ;
199+ for ( let i = index ; i < editableTranscription . value . length ; i ++ ) {
200+ editableTranscription . value [ i ] . id = i ;
201+ transcription . value [ i ] . id = i ;
202+ }
203+ }
204+
205+ function appendSegment ( ) {
206+ const lastSegment = editableTranscription . value . at ( - 1 ) ;
207+ if ( ! lastSegment ?. end ) return ;
208+ const newSegment = {
209+ start : lastSegment . end ,
210+ end : lastSegment . end + 6 ,
211+ text : "" ,
212+ isHeader : false ,
213+ id : editableTranscription . value . length ,
214+ } ;
215+ editableTranscription . value . push ( newSegment ) ;
216+ transcription . value ?. push ( structuredClone ( toRaw ( newSegment ) ) ) ;
217+ }
218+
184219 return {
185220 currentIndex,
186221 transcription,
@@ -198,5 +233,7 @@ export function useTranscriptionTool(options: UseTranscriptionToolOptions) {
198233 toggleDeletion,
199234 deletedTranscriptionSegments,
200235 refetchTranscription,
236+ addSegment,
237+ appendSegment,
201238 } ;
202239}
0 commit comments