@@ -91,6 +91,8 @@ let AdvancedEditor = () => {
91
91
isPlaying,
92
92
defaultClipSize,
93
93
videoLength,
94
+ offset,
95
+ actualVideoLength,
94
96
} ;
95
97
const keyboardHandler = useCallback ( ( event ) => {
96
98
if ( isActiveElementInput ( ) ) {
@@ -120,58 +122,42 @@ let AdvancedEditor = () => {
120
122
break ;
121
123
}
122
124
case 'ArrowLeft' : {
123
- setCurrentSliderPosition ( ( currentSliderPosition ) =>
124
- Math . max ( 0 , currentSliderPosition - 1000 )
125
- ) ;
126
- setCurrentPosition (
125
+ scrub (
127
126
Math . max (
128
- 0 ,
129
- stateRef . current . currentSliderPosition / 1000 - 1
127
+ 0 + stateRef . current . offset ,
128
+ stateRef . current . currentSliderPosition - 1000
130
129
)
131
130
) ;
132
131
133
132
break ;
134
133
}
135
134
case 'ArrowRight' : {
136
- setCurrentSliderPosition ( ( currentSliderPosition ) =>
135
+ scrub (
137
136
Math . min (
138
- stateRef . current . videoLength * 1000 ,
139
- currentSliderPosition + 1000
140
- )
141
- ) ;
142
- setCurrentPosition (
143
- Math . min (
144
- stateRef . current . videoLength ,
145
- stateRef . current . currentSliderPosition / 1000 + 1
137
+ stateRef . current . currentSliderPosition + 1000 ,
138
+ stateRef . current . videoLength * 1000 +
139
+ stateRef . current . offset
146
140
)
147
141
) ;
148
142
149
143
break ;
150
144
}
151
145
case ';' : {
152
- setCurrentSliderPosition ( ( currentSliderPosition ) =>
153
- Math . max ( 0 , currentSliderPosition - 1000 / 60 )
154
- ) ;
155
- setCurrentPosition (
146
+ scrub (
156
147
Math . max (
157
- 0 ,
158
- stateRef . current . currentSliderPosition / 1000 - 1 / 60
148
+ 0 + stateRef . current . offset ,
149
+ stateRef . current . currentSliderPosition - 1000 / 60
159
150
)
160
151
) ;
161
152
162
153
break ;
163
154
}
164
155
case "'" : {
165
- setCurrentSliderPosition ( ( currentSliderPosition ) =>
156
+ scrub (
166
157
Math . min (
167
- stateRef . current . videoLength * 1000 ,
168
- currentSliderPosition + 1000 / 60
169
- )
170
- ) ;
171
- setCurrentPosition (
172
- Math . min (
173
- stateRef . current . videoLength ,
174
- stateRef . current . currentSliderPosition / 1000 + 1 / 60
158
+ stateRef . current . currentSliderPosition + 1000 / 60 ,
159
+ stateRef . current . videoLength * 1000 +
160
+ stateRef . current . offset
175
161
)
176
162
) ;
177
163
@@ -184,7 +170,9 @@ let AdvancedEditor = () => {
184
170
'edit' ,
185
171
{
186
172
...currentSubObject ,
187
- startTime : stateRef . current . currentSliderPosition ,
173
+ startTime :
174
+ stateRef . current . currentSliderPosition -
175
+ stateRef . current . offset ,
188
176
} ,
189
177
stateRef . current . currentSub
190
178
) ;
@@ -197,7 +185,9 @@ let AdvancedEditor = () => {
197
185
'edit' ,
198
186
{
199
187
...currentSubObject ,
200
- endTime : stateRef . current . currentSliderPosition ,
188
+ endTime :
189
+ stateRef . current . currentSliderPosition -
190
+ stateRef . current . offset ,
201
191
} ,
202
192
stateRef . current . currentSub
203
193
) ;
@@ -206,15 +196,13 @@ let AdvancedEditor = () => {
206
196
case '[' : {
207
197
let currentSubObject =
208
198
stateRef . current . subs [ stateRef . current . currentSub ] ;
209
- setCurrentSliderPosition ( currentSubObject . startTime ) ;
210
- setCurrentPosition ( currentSubObject . startTime / 1000 ) ;
199
+ scrub ( currentSubObject . startTime + stateRef . current . offset ) ;
211
200
break ;
212
201
}
213
202
case ']' : {
214
203
let currentSubObject =
215
204
stateRef . current . subs [ stateRef . current . currentSub ] ;
216
- setCurrentSliderPosition ( currentSubObject . endTime ) ;
217
- setCurrentPosition ( currentSubObject . endTime / 1000 ) ;
205
+ scrub ( currentSubObject . endTime + stateRef . current . offset ) ;
218
206
break ;
219
207
}
220
208
case 'w' : {
@@ -228,9 +216,12 @@ let AdvancedEditor = () => {
228
216
case 'n' :
229
217
subChangeHandler ( 'add' , {
230
218
rowIndex : stateRef . current . currentRow ,
231
- startTime : parseInt ( stateRef . current . currentSliderPosition ) ,
219
+ startTime :
220
+ parseInt ( stateRef . current . currentSliderPosition ) -
221
+ stateRef . current . offset ,
232
222
endTime :
233
- parseInt ( stateRef . current . currentSliderPosition ) +
223
+ parseInt ( stateRef . current . currentSliderPosition ) -
224
+ stateRef . current . offset +
234
225
stateRef . current . defaultClipSize ,
235
226
text : '' ,
236
227
type : 'subtitle' ,
@@ -251,13 +242,14 @@ let AdvancedEditor = () => {
251
242
break ;
252
243
}
253
244
event . stopPropagation ( ) ;
245
+ event . preventDefault ( ) ;
254
246
} ) ;
255
247
256
248
const getCurrentIndex = ( ) => {
257
249
let index = subs . findIndex ( ( subtitle ) => {
258
250
return (
259
- currentSliderPosition > subtitle . startTime &&
260
- currentSliderPosition < subtitle . endTime
251
+ currentSliderPosition > subtitle . startTime + offset &&
252
+ currentSliderPosition < subtitle . endTime + offset
261
253
) ;
262
254
} ) ;
263
255
@@ -404,10 +396,12 @@ let AdvancedEditor = () => {
404
396
let scrub = ( milliseconds ) => {
405
397
if ( milliseconds < 0 ) {
406
398
milliseconds = 0 ;
407
- } else if ( milliseconds > actualVideoLength * 1000 ) {
408
- milliseconds = videoLength * 1000 ;
399
+ } else if ( milliseconds > stateRef . current . actualVideoLength * 1000 ) {
400
+ milliseconds = stateRef . current . videoLength * 1000 ;
409
401
}
410
402
403
+ console . log ( 'SCRUB TO ' + milliseconds ) ;
404
+
411
405
setCurrentPosition ( milliseconds / 1000 ) ;
412
406
setCurrentSliderPosition ( milliseconds ) ;
413
407
setIsPlaying ( false ) ;
0 commit comments