mirror of
https://github.com/mifi/lossless-cut.git
synced 2024-11-22 02:12:30 +01:00
implement option to shift segments start/end/both
This commit is contained in:
parent
89d8745fdf
commit
09336f99cd
@ -26,7 +26,7 @@
|
||||
"no-promise-executor-return": 0,
|
||||
"react/function-component-definition": 0
|
||||
},
|
||||
"parserOptions": {
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2022
|
||||
}
|
||||
}
|
||||
|
15
src/App.jsx
15
src/App.jsx
@ -415,10 +415,17 @@ const App = memo(() => {
|
||||
}, [currentSegIndexSafe, getSegApparentEnd, currentCutSeg, duration, updateSegAtIndex]);
|
||||
|
||||
const shiftAllSegmentTimes = useCallback(async () => {
|
||||
const shiftValue = await askForShiftSegments();
|
||||
if (shiftValue == null) return;
|
||||
const clampValue = (val) => Math.min(Math.max(val + shiftValue, 0), duration);
|
||||
const newSegments = apparentCutSegments.map((segment) => ({ ...segment, start: clampValue(segment.start + shiftValue), end: clampValue(segment.end + shiftValue) })).filter((segment) => segment.end > segment.start);
|
||||
const shift = await askForShiftSegments();
|
||||
if (shift == null) return;
|
||||
const { shiftAmount, shiftValues } = shift;
|
||||
const clampValue = (val) => Math.min(Math.max(val + shiftAmount, 0), duration);
|
||||
const newSegments = apparentCutSegments.map((segment) => {
|
||||
const newSegment = { ...segment };
|
||||
shiftValues.forEach((key) => {
|
||||
newSegment[key] = clampValue(segment[key] + shiftAmount);
|
||||
});
|
||||
return newSegment;
|
||||
}).filter((segment) => segment.end > segment.start);
|
||||
if (newSegments.length < 1) setCutSegments(createInitialCutSegments());
|
||||
else setCutSegments(newSegments);
|
||||
}, [apparentCutSegments, createInitialCutSegments, duration, setCutSegments]);
|
||||
|
@ -8,7 +8,7 @@ import SyntaxHighlighter from 'react-syntax-highlighter';
|
||||
import { tomorrow as style } from 'react-syntax-highlighter/dist/esm/styles/hljs';
|
||||
import JSON5 from 'json5';
|
||||
|
||||
import { parseDuration } from './util/duration';
|
||||
import { parseDuration, formatDuration } from './util/duration';
|
||||
import { parseYouTube } from './edlFormats';
|
||||
import CopyClipboardButton from './components/CopyClipboardButton';
|
||||
|
||||
@ -239,6 +239,21 @@ async function askForSegmentDuration(fileDuration) {
|
||||
return parseDuration(value);
|
||||
}
|
||||
|
||||
async function askForShiftSegmentsVariant(time) {
|
||||
const { value } = await Swal.fire({
|
||||
input: 'radio',
|
||||
showCancelButton: true,
|
||||
inputOptions: {
|
||||
start: i18n.t('Start'),
|
||||
end: i18n.t('End'),
|
||||
both: i18n.t('Both'),
|
||||
},
|
||||
inputValue: 'both',
|
||||
text: i18n.t('Do you want to shift the start or end timestamp by {{time}}?', { time: formatDuration({ seconds: time, shorten: true }) }),
|
||||
});
|
||||
return value;
|
||||
}
|
||||
|
||||
export async function askForShiftSegments() {
|
||||
function parseValue(value) {
|
||||
let parseableValue = value;
|
||||
@ -267,7 +282,15 @@ export async function askForShiftSegments() {
|
||||
});
|
||||
|
||||
if (value == null) return undefined;
|
||||
return parseValue(value);
|
||||
const parsed = parseValue(value);
|
||||
|
||||
const shiftVariant = await askForShiftSegmentsVariant(parsed);
|
||||
if (shiftVariant == null) return undefined;
|
||||
|
||||
return {
|
||||
shiftAmount: parsed,
|
||||
shiftValues: shiftVariant === 'both' ? ['start', 'end'] : [shiftVariant],
|
||||
};
|
||||
}
|
||||
|
||||
export async function askForMetadataKey() {
|
||||
|
Loading…
Reference in New Issue
Block a user