mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-22 15:38:19 +00:00
fix(webui): fix arrow key frame rounding and duplicate event bubbling
- Use Math.round instead of Math.floor for keyboard arrow frame navigation in ModelViewer - Add e.stopPropagation() to RulerSlider keyboard events to prevent duplicate bubbling to window listener
This commit is contained in:
@@ -104,6 +104,14 @@ describe('ModelViewer', () => {
|
||||
fireEvent.keyDown(window, { key: 'ArrowRight' })
|
||||
expect(onTimeUpdate).toHaveBeenCalledWith(expect.closeTo(1 / 6, 2))
|
||||
|
||||
// Press ArrowRight second time -> advance to frame 2 (30 deg = 2/6 sec)
|
||||
fireEvent.keyDown(window, { key: 'ArrowRight' })
|
||||
expect(onTimeUpdate).toHaveBeenCalledWith(expect.closeTo(2 / 6, 2))
|
||||
|
||||
// Press ArrowLeft -> back 1 frame (frame 1 = 1/6 sec)
|
||||
fireEvent.keyDown(window, { key: 'ArrowLeft' })
|
||||
expect(onTimeUpdate).toHaveBeenCalledWith(expect.closeTo(1 / 6, 2))
|
||||
|
||||
// Press ArrowLeft -> back 1 frame (frame 0 = 0 sec)
|
||||
fireEvent.keyDown(window, { key: 'ArrowLeft' })
|
||||
expect(onTimeUpdate).toHaveBeenCalledWith(0)
|
||||
|
||||
@@ -167,11 +167,11 @@ export const ModelViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
togglePlay()
|
||||
} else if (e.key === 'ArrowLeft') {
|
||||
e.preventDefault()
|
||||
const currentFrame = Math.floor(currentTime * FPS)
|
||||
const currentFrame = Math.round(currentTime * FPS)
|
||||
seekToFrame(currentFrame - 1)
|
||||
} else if (e.key === 'ArrowRight') {
|
||||
e.preventDefault()
|
||||
const currentFrame = Math.floor(currentTime * FPS)
|
||||
const currentFrame = Math.round(currentTime * FPS)
|
||||
seekToFrame(currentFrame + 1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,15 +85,19 @@ export const RulerSlider: React.FC<RulerSliderProps> = ({
|
||||
if (disabled) return
|
||||
if (e.key === 'ArrowLeft' || e.key === 'ArrowDown') {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
onChange((((normalizedDegree - STEP) % 360) + 360) % 360)
|
||||
} else if (e.key === 'ArrowRight' || e.key === 'ArrowUp') {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
onChange((normalizedDegree + STEP) % 360)
|
||||
} else if (e.key === 'Home') {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
onChange(0)
|
||||
} else if (e.key === 'End') {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
onChange(345)
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user