fix(core): editor pgup/pgdn issues (#6331)

fix https://github.com/toeverything/AFFiNE/issues/6232
This commit is contained in:
pengx17
2024-03-27 04:47:31 +00:00
parent 5dcb3d69e5
commit 5ca17c155a

View File

@@ -27,13 +27,14 @@ import {
} from '@toeverything/infra'; } from '@toeverything/infra';
import clsx from 'clsx'; import clsx from 'clsx';
import { useSetAtom } from 'jotai'; import { useSetAtom } from 'jotai';
import type { ReactElement } from 'react'; import type { KeyboardEventHandler, ReactElement } from 'react';
import { import {
memo, memo,
useCallback, useCallback,
useEffect, useEffect,
useLayoutEffect, useLayoutEffect,
useMemo, useMemo,
useRef,
useState, useState,
} from 'react'; } from 'react';
import { useParams } from 'react-router-dom'; import { useParams } from 'react-router-dom';
@@ -202,6 +203,17 @@ const DetailPageImpl = memo(function DetailPageImpl() {
); );
const isWindowsDesktop = environment.isDesktop && environment.isWindows; const isWindowsDesktop = environment.isDesktop && environment.isWindows;
const scrollableRef = useRef<HTMLDivElement>(null);
const keydownHandler: KeyboardEventHandler = useCallback(e => {
// prevent pgup/pgdown from scrolling the page
if (e.key === 'PageUp' || e.key === 'PageDown') {
e.preventDefault();
scrollableRef.current?.scrollBy({
top: e.key === 'PageUp' ? -window.innerHeight : window.innerHeight,
behavior: 'smooth',
});
}
}, []);
return ( return (
<> <>
@@ -218,6 +230,8 @@ const DetailPageImpl = memo(function DetailPageImpl() {
<TopTip pageId={currentPageId} workspace={currentWorkspace} /> <TopTip pageId={currentPageId} workspace={currentWorkspace} />
<Scrollable.Root> <Scrollable.Root>
<Scrollable.Viewport <Scrollable.Viewport
ref={scrollableRef}
onKeyDown={keydownHandler}
className={clsx( className={clsx(
'affine-page-viewport', 'affine-page-viewport',
styles.affineDocViewport, styles.affineDocViewport,