mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 21:27:20 +00:00
feat(core): remember the scroll position of doc when routing forward and backward (#8631)
close AF-1011 https://github.com/user-attachments/assets/d2dfeee2-926f-4760-b3fb-8baf5ff90aa9
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { notify, Scrollable, useHasScrollTop } from '@affine/component';
|
||||
import { notify, Scrollable } from '@affine/component';
|
||||
import { PageDetailSkeleton } from '@affine/component/page-detail-skeleton';
|
||||
import type { ChatPanel } from '@affine/core/blocksuite/presets/ai';
|
||||
import { AIProvider } from '@affine/core/blocksuite/presets/ai';
|
||||
@@ -33,7 +33,7 @@ import {
|
||||
WorkspaceService,
|
||||
} from '@toeverything/infra';
|
||||
import clsx from 'clsx';
|
||||
import { memo, useCallback, useEffect, useRef } from 'react';
|
||||
import { memo, useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
|
||||
import { AffineErrorBoundary } from '../../../../components/affine/affine-error-boundary';
|
||||
@@ -227,28 +227,36 @@ const DetailPageImpl = memo(function DetailPageImpl() {
|
||||
})
|
||||
);
|
||||
|
||||
editor.setEditorContainer(editorContainer);
|
||||
const unbind = editor.bindEditorContainer(
|
||||
editorContainer,
|
||||
(editorContainer as any).docTitle // set from proxy
|
||||
(editorContainer as any).docTitle, // set from proxy
|
||||
scrollViewportRef.current
|
||||
);
|
||||
|
||||
return () => {
|
||||
unbind();
|
||||
editor.setEditorContainer(null);
|
||||
disposable.dispose();
|
||||
};
|
||||
},
|
||||
[editor, openPage, docCollection.id, jumpToPageBlock, t]
|
||||
);
|
||||
|
||||
const [refCallback, hasScrollTop] = useHasScrollTop();
|
||||
const [hasScrollTop, setHasScrollTop] = useState(false);
|
||||
|
||||
const openOutlinePanel = useCallback(() => {
|
||||
workbench.openSidebar();
|
||||
view.activeSidebarTab('outline');
|
||||
}, [workbench, view]);
|
||||
|
||||
const scrollViewportRef = useRef<HTMLDivElement | null>(null);
|
||||
|
||||
const handleScroll = useCallback((e: React.UIEvent<HTMLDivElement>) => {
|
||||
const scrollTop = e.currentTarget.scrollTop;
|
||||
|
||||
const hasScrollTop = scrollTop > 0;
|
||||
setHasScrollTop(hasScrollTop);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<FrameworkScope scope={editor.scope}>
|
||||
<ViewHeader>
|
||||
@@ -265,7 +273,8 @@ const DetailPageImpl = memo(function DetailPageImpl() {
|
||||
<TopTip pageId={doc.id} workspace={workspace} />
|
||||
<Scrollable.Root>
|
||||
<Scrollable.Viewport
|
||||
ref={refCallback}
|
||||
onScroll={handleScroll}
|
||||
ref={scrollViewportRef}
|
||||
className={clsx(
|
||||
'affine-page-viewport',
|
||||
styles.affineDocViewport,
|
||||
|
||||
@@ -234,11 +234,7 @@ const SharePageInner = ({
|
||||
if (!editor) {
|
||||
return;
|
||||
}
|
||||
editor.setEditorContainer(editorContainer);
|
||||
const unbind = editor.bindEditorContainer(
|
||||
editorContainer,
|
||||
(editorContainer as any).docTitle
|
||||
);
|
||||
const unbind = editor.bindEditorContainer(editorContainer);
|
||||
|
||||
const disposable = new DisposableGroup();
|
||||
const refNodeSlots =
|
||||
@@ -263,7 +259,6 @@ const SharePageInner = ({
|
||||
|
||||
return () => {
|
||||
unbind();
|
||||
editor.setEditorContainer(null);
|
||||
};
|
||||
},
|
||||
[editor, setActiveBlocksuiteEditor, jumpToPageBlock, openPage, workspaceId]
|
||||
|
||||
Reference in New Issue
Block a user