Skip to content

Commit

Permalink
Add new keyboard shortcuts to improve UX
Browse files Browse the repository at this point in the history
  • Loading branch information
remarcable committed Nov 17, 2023
1 parent 8e05dc3 commit dc25d3a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/components/HelpDialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ const SHORTCUTS = [
{ key: "l", action: "Rewind 10 seconds" },
{ key: "← (Left Arrow)", action: "Fast forward 5 seconds" },
{ key: "→ (Right Arrow)", action: "Rewind 5 seconds" },
{ key: "Space", action: "Set Marker" },
{ key: "Shift + Space", action: "Set Jump Marker" },
{ key: "Enter", action: "Rewind to start" },
{ key: "Backspace", action: "Remove selected marker" },
{ key: "Space", action: "Set marker" },
{ key: "Shift + Space", action: "Set jump marker" },
] as const;

const HelpDialog: React.FC<HelpDialogProps> = ({ open, handleClose }) => {
Expand Down
6 changes: 6 additions & 0 deletions src/components/Player/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const Player: React.FC = () => {
() => dispatch(playerActions.addMeasureMarker()),
[dispatch]
);
const removeCurrentMarker = useCallback(
() => dispatch(playerActions.removeCurrentMarker()),
[dispatch]
);
const openJumpMarkerDialog = useCallback(
() => dispatch(playerActions.openJumpMarkerDialog()),
[dispatch]
Expand All @@ -47,7 +51,9 @@ const Player: React.FC = () => {
togglePlaying,
addMeasureMarker,
openJumpMarkerDialog,
removeCurrentMarker,
relativeSeek,
absoluteSeek,
});

return (
Expand Down
7 changes: 7 additions & 0 deletions src/hooks/usePlayerHotkeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ export const usePlayerHotkeys = ({
togglePlaying,
addMeasureMarker,
openJumpMarkerDialog,
removeCurrentMarker,
relativeSeek,
absoluteSeek,
}: {
dialogIsOpen: boolean;
togglePlaying: () => void;
addMeasureMarker: () => void;
openJumpMarkerDialog: () => void;
removeCurrentMarker: () => void;
relativeSeek: (seconds: number) => void;
absoluteSeek: (seconds: number) => void;
}) => {
useHotkeys(
"k",
Expand Down Expand Up @@ -43,8 +47,11 @@ export const usePlayerHotkeys = ({
[openJumpMarkerDialog]
);

useHotkeys("backspace", () => removeCurrentMarker(), [removeCurrentMarker]);

useHotkeys("j", () => relativeSeek(-10), [relativeSeek]);
useHotkeys("l", () => relativeSeek(+10), [relativeSeek]);
useHotkeys("left", () => relativeSeek(-5), [relativeSeek]);
useHotkeys("right", () => relativeSeek(+5), [relativeSeek]);
useHotkeys("enter", () => absoluteSeek(0), [absoluteSeek]);
};
11 changes: 11 additions & 0 deletions src/state/playerSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ export const playerSlice = createSlice({
const { markers } = state;
const index = markers.findIndex((m) => m.time === action.payload);

if (index !== -1) {
markers.splice(index, 1);
}
},
removeCurrentMarker: (state) => {
const { time, markers } = state;
const index = markers.findIndex(
(m) => time - 0.01 <= m.time && m.time <= time + 0.01
);
console.log(time, index);

if (index !== -1) {
markers.splice(index, 1);
}
Expand Down

0 comments on commit dc25d3a

Please sign in to comment.