From 6e0c3bc5e3e2437a51fa991940b4e4496ed2bb75 Mon Sep 17 00:00:00 2001 From: Innei Date: Tue, 10 Sep 2024 19:28:14 +0800 Subject: [PATCH] feat: support pageup/pagedown to scroll up/down Signed-off-by: Innei --- src/renderer/src/constants/shortcuts.ts | 20 ++++++++----------- .../src/modules/entry-content/index.tsx | 10 ++++++++++ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/renderer/src/constants/shortcuts.ts b/src/renderer/src/constants/shortcuts.ts index 158841b885..7ae7497a94 100644 --- a/src/renderer/src/constants/shortcuts.ts +++ b/src/renderer/src/constants/shortcuts.ts @@ -2,18 +2,6 @@ import { COPY_MAP } from "@renderer/constants" export const shortcuts = { feeds: { - // previous: { - // name: "Previous Subscription", - // key: "P", - // }, - // next: { - // name: "Next Subscription", - // key: "N", - // }, - // toggleFolder: { - // name: "Toggle Folder", - // key: "X", - // }, add: { name: "Add Subscription", key: "Meta+T", @@ -85,6 +73,14 @@ export const shortcuts = { name: "Share", key: "Meta+Alt+S", }, + scrollUp: { + name: "Scroll Up", + key: "PageUp", + }, + scrollDown: { + name: "Scroll Down", + key: "PageDown", + }, }, audio: { diff --git a/src/renderer/src/modules/entry-content/index.tsx b/src/renderer/src/modules/entry-content/index.tsx index 7254895979..516d2a3751 100644 --- a/src/renderer/src/modules/entry-content/index.tsx +++ b/src/renderer/src/modules/entry-content/index.tsx @@ -16,6 +16,7 @@ import { useInPeekModal } from "@renderer/components/ui/modal/inspire/PeekModal" import { RootPortal } from "@renderer/components/ui/portal" import { ScrollArea } from "@renderer/components/ui/scroll-area" import { isWebBuild, ROUTE_FEED_PENDING } from "@renderer/constants" +import { shortcuts } from "@renderer/constants/shortcuts" import { useEntryReadabilityToggle } from "@renderer/hooks/biz/useEntryActions" import { useRouteParamsSelector, useRouteParms } from "@renderer/hooks/biz/useRouteParams" import { useAuthQuery, useTitle } from "@renderer/hooks/common" @@ -36,6 +37,7 @@ import type { FallbackRender } from "@sentry/react" import { ErrorBoundary } from "@sentry/react" import type { FC } from "react" import { useEffect, useLayoutEffect, useRef } from "react" +import { useHotkeys } from "react-hotkeys-hook" import { LoadingWithIcon } from "../../components/ui/loading" import { EntryPlaceholderDaily } from "../ai/ai-daily/EntryPlaceholderDaily" @@ -125,6 +127,14 @@ export const EntryContentRender: Component<{ entryId: string }> = ({ entryId, cl scrollerRef.current?.scrollTo(0, 0) }, [entryId]) + useHotkeys(shortcuts.entry.scrollDown.key, () => { + scrollerRef.current?.scrollBy(0, window.innerHeight / 2) + }) + + useHotkeys(shortcuts.entry.scrollUp.key, () => { + scrollerRef.current?.scrollBy(0, -window.innerHeight / 2) + }) + const isPeekModal = useInPeekModal() if (!entry) return null