feat: Initial clean release of CHM
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
这个提交包含在:
@@ -0,0 +1,66 @@
|
||||
import { useRef, useEffect, MutableRefObject, useState } from 'react';
|
||||
import PdfDocument from '../PdfDocument';
|
||||
import { ScaledSize } from '../types';
|
||||
|
||||
export interface ScrollSaver {
|
||||
container: MutableRefObject<HTMLElement>;
|
||||
scaledSize: ScaledSize;
|
||||
pdfId: string;
|
||||
rememberScroll: boolean;
|
||||
onActivePageChange: (activePage: number)=> void;
|
||||
pdfDocument: PdfDocument;
|
||||
pageGap: number;
|
||||
}
|
||||
|
||||
const useScrollSaver = ({ container, scaledSize, pdfId, rememberScroll, onActivePageChange, pdfDocument, pageGap }: ScrollSaver) => {
|
||||
const currentScaleSize = useRef(scaledSize);
|
||||
const [currentActivePage, setCurrentActivePage] = useState(1);
|
||||
const currentActivePageRef = useRef(currentActivePage);
|
||||
|
||||
useEffect(() => {
|
||||
let scrollTimer: number = null;
|
||||
const containerElement = container.current;
|
||||
|
||||
const saveScroll = () => {
|
||||
if (!currentScaleSize.current) return;
|
||||
const scale = currentScaleSize.current.scale;
|
||||
const pdfScrollTop = container.current.scrollTop / scale;
|
||||
if (rememberScroll && pdfId) {
|
||||
sessionStorage.setItem(`pdf.${pdfId}.scrollTop`, `${pdfScrollTop}`);
|
||||
}
|
||||
if (onActivePageChange && currentScaleSize.current) {
|
||||
const activePage = pdfDocument.getActivePageNo(currentScaleSize.current, pageGap, container.current.scrollTop);
|
||||
if (currentActivePageRef.current !== activePage) {
|
||||
// console.log('Active page changed', activePage, container.current.scrollTop);
|
||||
currentActivePageRef.current = activePage;
|
||||
onActivePageChange(activePage);
|
||||
setCurrentActivePage(activePage);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const onScroll = () => {
|
||||
if (scrollTimer) {
|
||||
clearTimeout(scrollTimer);
|
||||
scrollTimer = null;
|
||||
}
|
||||
scrollTimer = window.setTimeout(saveScroll, 200);
|
||||
};
|
||||
|
||||
containerElement.addEventListener('scroll', onScroll);
|
||||
|
||||
return () => {
|
||||
containerElement.removeEventListener('scroll', onScroll);
|
||||
if (scrollTimer) {
|
||||
clearTimeout(scrollTimer);
|
||||
scrollTimer = null;
|
||||
}
|
||||
};
|
||||
}, [container, pdfId, rememberScroll, currentScaleSize, onActivePageChange, pdfDocument, pageGap]);
|
||||
|
||||
useEffect(() => {
|
||||
currentScaleSize.current = scaledSize;
|
||||
}, [scaledSize]);
|
||||
};
|
||||
|
||||
export default useScrollSaver;
|
||||
在新工单中引用
屏蔽一个用户