Skip to content

Build your personal knowledge base with Trilium Notes

client/image viewer: ignore media track keys from sibling navigation

Adorian Doran5770650f1a39
diff --git a/apps/client/src/widgets/react/sibling_navigation.spec.ts b/apps/client/src/widgets/react/sibling_navigation.spec.ts
index 2b6eb86b52..26e08fadab 100644
--- a/apps/client/src/widgets/react/sibling_navigation.spec.ts
+++ b/apps/client/src/widgets/react/sibling_navigation.spec.ts
@@ -45,9 +45,9 @@ describe("codeToSiblingDirection", () => {
expect(codeToSiblingDirection("End", [], [])).toBe("last");
});
- it("maps the Previous/Next Track media keys", () => {
- expect(codeToSiblingDirection("MediaTrackPrevious", [], [])).toBe("previous");
- expect(codeToSiblingDirection("MediaTrackNext", [], [])).toBe("next");
+ it("ignores the Previous/Next Track media keys (OS media-key integration is video/audio-only)", () => {
+ expect(codeToSiblingDirection("MediaTrackPrevious", [], [])).toBeNull();
+ expect(codeToSiblingDirection("MediaTrackNext", [], [])).toBeNull();
});
it("honors caller-provided extra keys (e.g. the image viewer's Backspace/Space)", () => {
diff --git a/apps/client/src/widgets/react/sibling_navigation.ts b/apps/client/src/widgets/react/sibling_navigation.ts
index 3931948e49..8692aa03ea 100644
--- a/apps/client/src/widgets/react/sibling_navigation.ts
+++ b/apps/client/src/widgets/react/sibling_navigation.ts
@@ -29,14 +29,16 @@ export function getSiblingNavigation(siblingNoteIds: string[], currentNoteId: st
export type SiblingDirection = "previous" | "next" | "first" | "last";
/**
- * Maps a `KeyboardEvent.code` to a navigation direction. PageUp/PageDown and the Previous/Next Track
- * media keys (prev/next) are built in, as are Home/End (first/last) unless `includeEdges` is false (e.g.
- * media players reserve Home/End for seeking); a renderer can supply extra codes for prev/next (e.g. the
- * image viewer adds `Backspace`/`Space`). Using `code` keeps it keyboard-layout independent.
+ * Maps a `KeyboardEvent.code` to a navigation direction. PageUp/PageDown (prev/next) are built in, as are
+ * Home/End (first/last) unless `includeEdges` is false (e.g. media players reserve Home/End for seeking); a
+ * renderer can supply extra codes for prev/next (e.g. the image viewer adds `Backspace`/`Space`). Using
+ * `code` keeps it keyboard-layout independent. The Previous/Next Track media keys are deliberately not
+ * handled here — OS media-key integration is wired only for video/audio (via `navigator.mediaSession`),
+ * where the hardware keys actually route reliably; for images it mostly never fired.
*/
export function codeToSiblingDirection(code: string, extraPrevious: readonly string[], extraNext: readonly string[], includeEdges = true): SiblingDirection | null {
- if (code === "PageUp" || code === "MediaTrackPrevious" || extraPrevious.includes(code)) return "previous";
- if (code === "PageDown" || code === "MediaTrackNext" || extraNext.includes(code)) return "next";
+ if (code === "PageUp" || extraPrevious.includes(code)) return "previous";
+ if (code === "PageDown" || extraNext.includes(code)) return "next";
if (includeEdges && code === "Home") return "first";
if (includeEdges && code === "End") return "last";
return null;