Skip to content

Commit 23390f0

Browse files
Fixed keyboard controls and normalized them to use scrub
1 parent 33f0dd8 commit 23390f0

File tree

4 files changed

+42
-44
lines changed

4 files changed

+42
-44
lines changed

src/renderer/components/ClipList.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ export default ({
144144
</td>
145145
<td>
146146
<button
147+
title="i"
147148
onClick={() => {
148149
onClipsChange(
149150
'edit',
@@ -171,6 +172,7 @@ export default ({
171172
</td>
172173
<td>
173174
<button
175+
title="o"
174176
onClick={() => {
175177
onClipsChange(
176178
'edit',

src/renderer/components/SubtitleList.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ export default ({
213213
</td>
214214
<td>
215215
<button
216+
title="i"
216217
onClick={() => {
217218
onSubsChange(
218219
'edit',
@@ -240,6 +241,7 @@ export default ({
240241
</td>
241242
<td>
242243
<button
244+
title="o"
243245
onClick={() => {
244246
onSubsChange(
245247
'edit',

src/renderer/components/TimeLine.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export default ({
9292
onClick={() => {
9393
onSliderPositionChange(
9494
Math.max(
95-
0,
95+
0 + offset,
9696
currentSliderPosition + offset - 1000
9797
)
9898
);
@@ -105,7 +105,7 @@ export default ({
105105
onClick={() => {
106106
onSliderPositionChange(
107107
Math.max(
108-
0,
108+
0 + offset,
109109
currentSliderPosition + offset - 1000 / 60
110110
)
111111
);

src/renderer/routes/editor/AdvancedEditor.jsx

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ let AdvancedEditor = () => {
9191
isPlaying,
9292
defaultClipSize,
9393
videoLength,
94+
offset,
95+
actualVideoLength,
9496
};
9597
const keyboardHandler = useCallback((event) => {
9698
if (isActiveElementInput()) {
@@ -120,58 +122,42 @@ let AdvancedEditor = () => {
120122
break;
121123
}
122124
case 'ArrowLeft': {
123-
setCurrentSliderPosition((currentSliderPosition) =>
124-
Math.max(0, currentSliderPosition - 1000)
125-
);
126-
setCurrentPosition(
125+
scrub(
127126
Math.max(
128-
0,
129-
stateRef.current.currentSliderPosition / 1000 - 1
127+
0 + stateRef.current.offset,
128+
stateRef.current.currentSliderPosition - 1000
130129
)
131130
);
132131

133132
break;
134133
}
135134
case 'ArrowRight': {
136-
setCurrentSliderPosition((currentSliderPosition) =>
135+
scrub(
137136
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
146140
)
147141
);
148142

149143
break;
150144
}
151145
case ';': {
152-
setCurrentSliderPosition((currentSliderPosition) =>
153-
Math.max(0, currentSliderPosition - 1000 / 60)
154-
);
155-
setCurrentPosition(
146+
scrub(
156147
Math.max(
157-
0,
158-
stateRef.current.currentSliderPosition / 1000 - 1 / 60
148+
0 + stateRef.current.offset,
149+
stateRef.current.currentSliderPosition - 1000 / 60
159150
)
160151
);
161152

162153
break;
163154
}
164155
case "'": {
165-
setCurrentSliderPosition((currentSliderPosition) =>
156+
scrub(
166157
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
175161
)
176162
);
177163

@@ -184,7 +170,9 @@ let AdvancedEditor = () => {
184170
'edit',
185171
{
186172
...currentSubObject,
187-
startTime: stateRef.current.currentSliderPosition,
173+
startTime:
174+
stateRef.current.currentSliderPosition -
175+
stateRef.current.offset,
188176
},
189177
stateRef.current.currentSub
190178
);
@@ -197,7 +185,9 @@ let AdvancedEditor = () => {
197185
'edit',
198186
{
199187
...currentSubObject,
200-
endTime: stateRef.current.currentSliderPosition,
188+
endTime:
189+
stateRef.current.currentSliderPosition -
190+
stateRef.current.offset,
201191
},
202192
stateRef.current.currentSub
203193
);
@@ -206,15 +196,13 @@ let AdvancedEditor = () => {
206196
case '[': {
207197
let currentSubObject =
208198
stateRef.current.subs[stateRef.current.currentSub];
209-
setCurrentSliderPosition(currentSubObject.startTime);
210-
setCurrentPosition(currentSubObject.startTime / 1000);
199+
scrub(currentSubObject.startTime + stateRef.current.offset);
211200
break;
212201
}
213202
case ']': {
214203
let currentSubObject =
215204
stateRef.current.subs[stateRef.current.currentSub];
216-
setCurrentSliderPosition(currentSubObject.endTime);
217-
setCurrentPosition(currentSubObject.endTime / 1000);
205+
scrub(currentSubObject.endTime + stateRef.current.offset);
218206
break;
219207
}
220208
case 'w': {
@@ -228,9 +216,12 @@ let AdvancedEditor = () => {
228216
case 'n':
229217
subChangeHandler('add', {
230218
rowIndex: stateRef.current.currentRow,
231-
startTime: parseInt(stateRef.current.currentSliderPosition),
219+
startTime:
220+
parseInt(stateRef.current.currentSliderPosition) -
221+
stateRef.current.offset,
232222
endTime:
233-
parseInt(stateRef.current.currentSliderPosition) +
223+
parseInt(stateRef.current.currentSliderPosition) -
224+
stateRef.current.offset +
234225
stateRef.current.defaultClipSize,
235226
text: '',
236227
type: 'subtitle',
@@ -251,13 +242,14 @@ let AdvancedEditor = () => {
251242
break;
252243
}
253244
event.stopPropagation();
245+
event.preventDefault();
254246
});
255247

256248
const getCurrentIndex = () => {
257249
let index = subs.findIndex((subtitle) => {
258250
return (
259-
currentSliderPosition > subtitle.startTime &&
260-
currentSliderPosition < subtitle.endTime
251+
currentSliderPosition > subtitle.startTime + offset &&
252+
currentSliderPosition < subtitle.endTime + offset
261253
);
262254
});
263255

@@ -404,10 +396,12 @@ let AdvancedEditor = () => {
404396
let scrub = (milliseconds) => {
405397
if (milliseconds < 0) {
406398
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;
409401
}
410402

403+
console.log('SCRUB TO ' + milliseconds);
404+
411405
setCurrentPosition(milliseconds / 1000);
412406
setCurrentSliderPosition(milliseconds);
413407
setIsPlaying(false);

0 commit comments

Comments
 (0)