diff --git a/CHANGELOG.md b/CHANGELOG.md index d100577..355aa4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ instead of version numbers. * PDFs now support typing a page number manually, which makes it easier to navigate large documents. [[#346](https://github.com/edemaine/coauthor/issues/346)] +* PDFs remember your previous page when you click on a link, + adding back/forward navigation buttons similar to browser back/forward. ## 2023-12-17 diff --git a/client/MessagePDF.coffee b/client/MessagePDF.coffee index 7755ed0..0dc94cc 100644 --- a/client/MessagePDF.coffee +++ b/client/MessagePDF.coffee @@ -44,6 +44,8 @@ WrappedMessagePDF = React.memo ({file}) -> [pageInput, setPageInput] = useState 1 [pageNum, setPageNum] = useState() [numPages, setNumPages] = useState() + [pageBack, setPageBack] = useState [] + [pageForward, setPageForward] = useState [] [fit, setFit] = useState 'page' theme = useMessageTheme file [dims, setDims] = useState {width: 0, height: 0} @@ -84,7 +86,7 @@ WrappedMessagePDF = React.memo ({file}) -> useEffect -> if pdf? and pageNum? pdf.getPage pageNum - .then (pageLoaded) -> setPage pageLoaded + .then (pageLoaded) => setPage pageLoaded else setPage undefined undefined @@ -156,6 +158,7 @@ WrappedMessagePDF = React.memo ({file}) -> -> renderTask.cancel() , [page, elementWidth, fit, inView] + ## Synchronize page input with navigation of page number useEffect => setPageInput pageNum if pageNum? , [pageNum] @@ -172,6 +175,14 @@ WrappedMessagePDF = React.memo ({file}) -> p = Math.round e.currentTarget.valueAsNumber if 1 <= p <= numPages setPageNum p + onPageBack = (e) => + setPageForward [pageNum, ...pageForward] + setPageNum pageBack[0] + setPageBack pageBack[1..] + onPageForward = (e) => + setPageBack [pageNum, ...pageBack] + setPageNum pageForward[0] + setPageForward pageForward[1..] onFit = (newFit) => (e) => e.currentTarget.blur() setFit newFit @@ -188,6 +199,22 @@ WrappedMessagePDF = React.memo ({file}) -> else <>