Repository navigation
feat(editor): support keyboard shortcuts for timeline start/end navigation (fixes #2120) #2978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
shuoYun114
wants to merge
4
commits into
CapSoftware:main
from
shuoYun114:feat/timeline-navigation-shortcuts
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c658632
feat(editor): support keyboard shortcuts for timeline start/end navig…
7774d07
fix(editor): address adversarial audit feedback on modifiers, bounds,…
239c68d
fix(shortcuts): address review feedback on handoff seeking, overlay n…
903d324
fix(editor): address greptile review on jsdom environment, zoom alias…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
apps/desktop/src/routes/editor/use-editor-shortcuts.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { normalizeCombo } from "./useEditorShortcuts"; | ||
|
|
||
| function createKeyboardEvent( | ||
| code: string, | ||
| options: { | ||
| metaKey?: boolean; | ||
| ctrlKey?: boolean; | ||
| altKey?: boolean; | ||
| shiftKey?: boolean; | ||
| } = {}, | ||
| ): KeyboardEvent { | ||
| return { | ||
| code, | ||
| metaKey: options.metaKey ?? false, | ||
| ctrlKey: options.ctrlKey ?? false, | ||
| altKey: options.altKey ?? false, | ||
| shiftKey: options.shiftKey ?? false, | ||
| } as KeyboardEvent; | ||
| } | ||
|
|
||
| describe("useEditorShortcuts: normalizeCombo", () => { | ||
| it("normalizes navigation and boundary keys without modifiers", () => { | ||
| expect(normalizeCombo(createKeyboardEvent("ArrowUp"))).toBe("ArrowUp"); | ||
| expect(normalizeCombo(createKeyboardEvent("ArrowDown"))).toBe("ArrowDown"); | ||
| expect(normalizeCombo(createKeyboardEvent("Home"))).toBe("Home"); | ||
| expect(normalizeCombo(createKeyboardEvent("End"))).toBe("End"); | ||
| expect(normalizeCombo(createKeyboardEvent("Space"))).toBe("Space"); | ||
| }); | ||
|
|
||
| it("strips Key prefix for standard letters", () => { | ||
| expect(normalizeCombo(createKeyboardEvent("KeyS"))).toBe("S"); | ||
| expect(normalizeCombo(createKeyboardEvent("KeyC"))).toBe("C"); | ||
| }); | ||
|
|
||
| it("normalizes Mod modifier and special symbols", () => { | ||
| expect(normalizeCombo(createKeyboardEvent("Equal", { metaKey: true }))).toBe("Mod+="); | ||
| expect(normalizeCombo(createKeyboardEvent("Equal", { metaKey: true, shiftKey: true }))).toBe("Mod+Shift+="); | ||
| expect(normalizeCombo(createKeyboardEvent("Minus", { ctrlKey: true }))).toBe("Mod+-"); | ||
| expect(normalizeCombo(createKeyboardEvent("KeyS", { metaKey: true }))).toBe("Mod+S"); | ||
| }); | ||
|
|
||
| it("preserves Shift and Alt modifiers to avoid collision with bare navigation keys", () => { | ||
| expect(normalizeCombo(createKeyboardEvent("ArrowUp", { shiftKey: true }))).toBe("Shift+ArrowUp"); | ||
| expect(normalizeCombo(createKeyboardEvent("ArrowDown", { altKey: true }))).toBe("Alt+ArrowDown"); | ||
| expect(normalizeCombo(createKeyboardEvent("Home", { ctrlKey: true, shiftKey: true }))).toBe("Mod+Shift+Home"); | ||
| expect(normalizeCombo(createKeyboardEvent("KeyS", { altKey: true }))).toBe("Alt+S"); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| // @vitest-environment jsdom | ||
| import { describe, expect, it } from "vitest"; | ||
| import { | ||
| isIgnoredTimelineKeyboardTarget, | ||
| resolveTimelineKeyAction, | ||
| } from "@/app/s/[videoId]/_components/timeline/TimelineView"; | ||
|
|
||
| describe("resolveTimelineKeyAction", () => { | ||
| it("seeks to start (0) on bare ArrowUp and Home when not focused on slider", () => { | ||
| expect(resolveTimelineKeyAction("ArrowUp", false, 120, false, false)).toEqual({ | ||
| type: "seekTo", | ||
| time: 0, | ||
| }); | ||
| expect(resolveTimelineKeyAction("Home", false, 120, false, false)).toEqual({ | ||
| type: "seekTo", | ||
| time: 0, | ||
| }); | ||
| }); | ||
|
|
||
| it("seeks to end on bare ArrowDown and End when not focused on slider", () => { | ||
| expect(resolveTimelineKeyAction("ArrowDown", false, 120, false, false)).toEqual({ | ||
| type: "seekTo", | ||
| time: 120, | ||
| }); | ||
| expect(resolveTimelineKeyAction("End", false, 120, false, false)).toEqual({ | ||
| type: "seekTo", | ||
| time: 120, | ||
| }); | ||
| }); | ||
|
|
||
| it("steps incrementally on ArrowUp/Down/Left/Right when focused on ARIA slider per accessibility guidelines", () => { | ||
| expect(resolveTimelineKeyAction("ArrowUp", false, 120, false, true)).toEqual({ | ||
| type: "seekDelta", | ||
| delta: 5, | ||
| }); | ||
| expect(resolveTimelineKeyAction("ArrowDown", false, 120, false, true)).toEqual({ | ||
| type: "seekDelta", | ||
| delta: -5, | ||
| }); | ||
| expect(resolveTimelineKeyAction("ArrowRight", false, 120, false, true)).toEqual({ | ||
| type: "seekDelta", | ||
| delta: 5, | ||
| }); | ||
| expect(resolveTimelineKeyAction("ArrowLeft", false, 120, false, true)).toEqual({ | ||
| type: "seekDelta", | ||
| delta: -5, | ||
| }); | ||
| expect(resolveTimelineKeyAction("Home", false, 120, false, true)).toEqual({ | ||
| type: "seekTo", | ||
| time: 0, | ||
| }); | ||
| expect(resolveTimelineKeyAction("End", false, 120, false, true)).toEqual({ | ||
| type: "seekTo", | ||
| time: 120, | ||
| }); | ||
| }); | ||
|
|
||
| it("handles non-finite or negative durations safely", () => { | ||
| expect(resolveTimelineKeyAction("ArrowDown", false, Number.NaN, false, false)).toEqual({ | ||
| type: "seekTo", | ||
| time: 0, | ||
| }); | ||
| expect(resolveTimelineKeyAction("End", false, -10, false, false)).toEqual({ | ||
| type: "seekTo", | ||
| time: 0, | ||
| }); | ||
| }); | ||
|
|
||
| it("seeks delta on ArrowLeft and ArrowRight", () => { | ||
| expect(resolveTimelineKeyAction("ArrowLeft", false, 120, false)).toEqual({ | ||
| type: "seekDelta", | ||
| delta: -5, | ||
| }); | ||
| expect(resolveTimelineKeyAction("ArrowRight", false, 120, false)).toEqual({ | ||
| type: "seekDelta", | ||
| delta: 5, | ||
| }); | ||
| }); | ||
|
|
||
| it("toggles play on Space unless focused over a branch node button", () => { | ||
| expect(resolveTimelineKeyAction(" ", false, 120, false)).toEqual({ | ||
| type: "togglePlay", | ||
| }); | ||
| expect(resolveTimelineKeyAction("Spacebar", false, 120, false)).toEqual({ | ||
| type: "togglePlay", | ||
| }); | ||
| expect(resolveTimelineKeyAction(" ", false, 120, true)).toBeNull(); | ||
| }); | ||
|
|
||
| it("strictly ignores actions when any modifier is pressed", () => { | ||
| expect(resolveTimelineKeyAction("ArrowUp", true, 120, false)).toBeNull(); | ||
| expect(resolveTimelineKeyAction("ArrowDown", true, 120, false)).toBeNull(); | ||
| expect(resolveTimelineKeyAction("Home", true, 120, false)).toBeNull(); | ||
| expect(resolveTimelineKeyAction("End", true, 120, false)).toBeNull(); | ||
| expect(resolveTimelineKeyAction("ArrowLeft", true, 120, false)).toBeNull(); | ||
| expect(resolveTimelineKeyAction("ArrowRight", true, 120, false)).toBeNull(); | ||
| expect(resolveTimelineKeyAction(" ", true, 120, false)).toBeNull(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("isIgnoredTimelineKeyboardTarget", () => { | ||
| it("returns false for null target or generic divs", () => { | ||
| expect(isIgnoredTimelineKeyboardTarget(null)).toBe(false); | ||
| const div = document.createElement("div"); | ||
| expect(isIgnoredTimelineKeyboardTarget(div)).toBe(false); | ||
| }); | ||
|
|
||
| it("returns true for input, textarea, select, contenteditable, and listbox/menu roles", () => { | ||
| const input = document.createElement("input"); | ||
| expect(isIgnoredTimelineKeyboardTarget(input)).toBe(true); | ||
|
|
||
| const textarea = document.createElement("textarea"); | ||
| expect(isIgnoredTimelineKeyboardTarget(textarea)).toBe(true); | ||
|
|
||
| const select = document.createElement("select"); | ||
| expect(isIgnoredTimelineKeyboardTarget(select)).toBe(true); | ||
|
|
||
| const editable = document.createElement("div"); | ||
| editable.contentEditable = "true"; | ||
| expect(isIgnoredTimelineKeyboardTarget(editable)).toBe(true); | ||
|
|
||
| const listbox = document.createElement("div"); | ||
| listbox.setAttribute("role", "listbox"); | ||
| expect(isIgnoredTimelineKeyboardTarget(listbox)).toBe(true); | ||
|
|
||
| const menu = document.createElement("div"); | ||
| menu.setAttribute("role", "menu"); | ||
| expect(isIgnoredTimelineKeyboardTarget(menu)).toBe(true); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests only check
normalizeCombo; they never dispatch a key throughuseEditorShortcutsor exercise the new handlers inPlayerContent. They would still pass if the boundary bindings were removed or the handoff and overlay guards broke. Add event-level tests for boundary seeking, pending handoff, and selected-overlay nudging.Prompt To Fix With AI
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!