-
Notifications
You must be signed in to change notification settings - Fork 327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Intersection Observers for getting "Current Page(s)" #3845
base: master
Are you sure you want to change the base?
Conversation
Bad commit here with too much stuff. I apologize. This sets up two Intersection Observers: the first captures every page that is at least 30% visible inside the `.pages` container, and the second captures every page that has at least one pixel on the horizontal center line of `.pages`. Both can be arrays of integers (page index). The "visiblePages" array is duplicated and formatted into a "formattedPages" state, which gets displayed in the toolbar. The toolbar displays that, unless the user clicks into the page input and enters their own integer (only a single integer, no range), which can then jump the preview to that page on Enter or blur(). The Arrow 'change page' buttons jump the preview back and forth by a 'full set'. If one page is viewed at a time, this is moved on page a time, and if 10 pages are viewed at a time it jumps the pages by 10. Left to do: adapt the "jump editor to match preview" divider button to work with new "centerPage".
This fixes the "jump editor to preview position" button.
Reduce the visual prominence of the page input by using a darker background and a text color that matches the rest of the toolbar icons. Darker background still indicates this is an interactive item (is an input), hopefully.
Removes currentPage as a variable since it's been replaced.
Little changes like removing console.logs and adding comments.
Doesn't need to be set in brewRenderer state and passed as a prop, when it can just do it's work directly in the toolbar.
When the toolbar showing 100% zoom and page displaying
Presumably this issue will also appear at other zoom levels. |
To be clear, are you saying that this expectation is met? Because when I do it,
Just want to be sure you are listing one problem, not two. |
When the toolbar showing 40% zoom and page displaying
So it appears that the Previous Page option is consistently selecting one page earlier than expected. |
Correct, Next Page is working within my intuitive expectations, while Previous Page is not. |
So it's taking the number of visible pages (3), walking back that number of pages from the "first in range" (or, subtracting 3 from 7), and then using that result to plug into Because you are only viewing partials of the 'top' and 'bottom' pages, you have 3 visible pages. But when I'll have to think about how this should be handled. edit: every subsequent click of the previous button would be fine as is currently setup |
Perhaps before calculating the next range to scroll to, I can call |
@G-Ambatte i pushed a change, see if it's better. The behavior still isn't entirely consistent between the "Previous" and the "Next" buttons, but it should no longer skip a whole page entirely. When you are viewing pages
When you are viewing pages
So basically when you are advancing a "page", it will show you the last page of your previous state plus whatever else registers as 'visible'. And when you are going back a "page", it will show you a completely new set of pages that immediately precede your previous set. When only one page is registered as "visible" it just works as expected. Is this acceptable? |
Sorry, just realized I didn't respond to this. From testing, it appears to operate as expected. Looks good! |
Prior to fix, the "next page" button in the toolbar wouldn't work well if there were multiple pages in view that were in a single 'row'. This is because the logic is to take the pages that are "visible", take the max of those pages, and then scroll to that page. But the issue is that if the 'max' page is in the same row as other pages, the range of visible pages doesn't change....the max will always be the same. So the change here basically runs the scroll function twice-- if the first run results in the same 'max' page as before the scroll, it runs it again but with the target page being "max + 1", which will bump the target to the next row.
Some changes made and things fixed. I think it's outlined well enough in the commit messages, but quick notes:
Oh, and, |
When the page is zoomed in very close, such that <30% of the page is in view, it doesn't register changes to the 'current page'. This fixes that, passing in the 'centerPage' if 'visiblePages' is empty. I don't love this fix, i think the visiblePages should always have *something* in it, but I can't quite figure out how to set that (since the normal update to visiblePages is happening in an observer that doesn't fire if nothing is in view).
The following is more like a personal take on this, but i think it can be useful, in the jsx for the page numebr input add a manual style attribute like so:
and in the CSS changing the width to set a This should keep a small input when a small value is set, and grow with it to a maximum we deem appropiate. It accounts for the number of characters in the pageNum string, plus 2 for good measure, acting like a faux padding. |
pretty much completely unchanged, was originally moved just to help with merging master in (ie it was erroneously removed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks great!
for (let i = 1; i <= sortedPages.length; i++) { | ||
// If the current page is not consecutive or it's the end of the list | ||
if(i === sortedPages.length || sortedPages[i] !== sortedPages[i - 1] + 1) { | ||
// Push the range to the list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as before, L91 comment doesn't add anything. Is this from the toaster?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It probably is a remainder from cGPT, though I'm not sure it should be removed. It's part of a series of comments on each step of the method, so it'd be odd to leave one step uncommented. Someone else can remove it or do whatever to resolve this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but a comment that says push the range to the list
, then the next line is range.push(
is pretty redundant IMO
This PR is mostly motivated by the work on the #3799 PR which allows users to view many pages at once, but was causing issues with what is the "current page" and also issues of viewing "page 10 out of 9 total pages"-like issues in the Toolbar.
Description
This sets up two Intersection Observers: the first captures every page that is at least 30% visible inside the
.pages
container, and the second captures every page that has at least one pixel on the horizontal center line of.pages
. Both can be arrays of integers (page index).The
visiblePages
array is duplicated and formatted into aformattedPages
state variable as strings, which gets displayed in the toolbar.visiblePages
is kept so that it can be used in the "previous/next page" buttons of the toolbar later.The toolbar displays the
formattedPages
strings, unless the user clicks into the page input and enters their own integer (only a single integer, no range), which can then jump the preview to that page on Enter or blur().The Arrow 'change page' buttons jump the preview back and forth by a 'full set'. Meaning that if you are viewing one page a time it will move through the previous/next pages one at a time, but if you are viewing 10 pages at once it will move you through 10 pages at a time.
Related Issues or Discussions
QA Instructions, Screenshots, Recordings
First, sorry for the bad single commit on this one, it doesn't really walk you through the development.
An example document (500 pages) with some additional styling to make it easy to see page numbers:
HB-NecromanticArmorofSaladDressing.txt
or, just put this CSS in any long brew:
To Test:
1 / [total pages]
in the toolbar.1
or the total page count without going over.10 - 12
. You can also change the current "Spread" to facing or flow.enter
or clicking outside of it-- it should take you to that page. Typing non-integer characters should be ignored, as well as ranges, and integers outside the total page count will bring you to the last page.Single page with >30% of area inside view:
Book spread, shows that only pages with >30% of area inside view are shown in the 'current pages' input:
Many pages, shows the "range":
Reviewer Checklist
No checklist yet. (I have to go to bed)
*Reviewers, refer to this list when testing features, or suggest new items *
flex
format (multiple pages in row)Copy this list