Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions frontend/src/components/ClipEditor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,17 +231,17 @@ describe('ClipEditor, deleting a clip', () => {
vi.spyOn(clipsApi, 'list').mockResolvedValue([])
const create = vi
.spyOn(clipsApi, 'create')
.mockResolvedValue({ ...liveClip, id: 'c4', in_point: 1.5, out_point: 12.01 })
.mockResolvedValue({ ...liveClip, id: 'c4', in_point: 1.5, out_point: 12.1 })
renderEditor()

await userEvent.type(await screen.findByLabelText('In point seconds'), '1')
await userEvent.type(screen.getByLabelText('In point milliseconds'), '500')
await userEvent.type(screen.getByLabelText('Out point seconds'), '11')
await userEvent.click(screen.getByRole('button', { name: 'Out point +1s' }))
await userEvent.click(screen.getByRole('button', { name: 'Out point +10ms' }))
await userEvent.click(screen.getByRole('button', { name: 'Out point +100ms' }))
await userEvent.click(screen.getByRole('button', { name: 'Save as clip' }))

expect(create).toHaveBeenCalledWith('a1', { in_point: 1.5, out_point: 12.01 })
expect(create).toHaveBeenCalledWith('a1', { in_point: 1.5, out_point: 12.1 })
})

it('stops a nudge at the end of the asset', async () => {
Expand All @@ -259,17 +259,17 @@ describe('ClipEditor, deleting a clip', () => {
vi.spyOn(clipsApi, 'list').mockResolvedValue([liveClip])
const setRange = vi
.spyOn(clipsApi, 'setRange')
.mockResolvedValue({ ...liveClip, in_point: 4.99, out_point: 9 })
.mockResolvedValue({ ...liveClip, in_point: 4.9, out_point: 9 })
renderEditor()

await userEvent.click(
await screen.findByRole('button', { name: "Edit this clip's times" })
)
// The new-clip fields are above; the row's form is the second pair.
await userEvent.click(screen.getAllByRole('button', { name: 'In point −10ms' })[1])
await userEvent.click(screen.getAllByRole('button', { name: 'In point −100ms' })[1])
await userEvent.click(screen.getByRole('button', { name: 'Save times' }))

expect(setRange).toHaveBeenCalledWith(liveClip.id, { in_point: 4.99, out_point: 9 })
expect(await screen.findByText('00:00:04:990 – 00:00:09:000')).toBeInTheDocument()
expect(setRange).toHaveBeenCalledWith(liveClip.id, { in_point: 4.9, out_point: 9 })
expect(await screen.findByText('00:00:04:900 – 00:00:09:000')).toBeInTheDocument()
})
})
12 changes: 6 additions & 6 deletions frontend/src/components/TimecodeInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { useEffect, useRef, useState } from 'react'
import { Crosshair, Play } from 'lucide-react'
import { fromTimecodeParts, toTimecodeParts, type TimecodeParts } from '@/utils/format'

/** The nudge buttons, smallest step innermost. Frames are 33–42 ms at common rates,
* so 10 ms is fine enough to land on one without a hundred presses. */
/** The nudge buttons, smallest step innermost. 100 ms is a few frames at common rates:
* quick to walk with, and the milliseconds field is there for anything finer. */
const NUDGES = [
{ delta: -1, label: '−1s' },
{ delta: -0.01, label: '−10ms' },
{ delta: 0.01, label: '+10ms' },
{ delta: -0.1, label: '−100ms' },
{ delta: 0.1, label: '+100ms' },
{ delta: 1, label: '+1s' },
]

Expand All @@ -33,8 +33,8 @@ interface Props {
setLabel?: string
}

/** Rounded to the millisecond, the precision the fields show: without it, ten +10 ms
* nudges from 0 land on 0.09999999999999999 and the display drifts a millisecond. */
/** Rounded to the millisecond, the precision the fields show: without it, three +100 ms
* nudges from 0 land on 0.30000000000000004, float noise that would be saved as is. */
function clamp(seconds: number, max: number | undefined): number {
const bounded = Math.max(0, max === undefined ? seconds : Math.min(seconds, max))
return Math.round(bounded * 1000) / 1000
Expand Down
Loading