-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
List View: Fix home and end key behaviour in very long lists #62312
List View: Fix home and end key behaviour in very long lists #62312
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: +13 B (0%) Total Size: 1.76 MB
ℹ️ View Unchanged
|
Just switching back to Draft while I look into test failures. |
@@ -1120,7 +1120,7 @@ test.describe( 'List View', () => { | |||
'Pressing keyboard shortcut should also work when the menu is opened and focused' | |||
) | |||
.toMatchObject( [ | |||
{ name: 'core/paragraph', selected: true, focused: false }, | |||
{ name: 'core/paragraph', selected: true, focused: true }, |
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.
This needed to be updated because it turns out this PR appears to resolve a subtle bug:
When you open the block settings menu dropdown for the last item in the list view and then use the insert before keyboard shortcut, prior to this PR, there's a tiny moment when the last block in the list evaluates to showBlock
being false
while blockInView
is being recalculated. That render then appears to mean that the focus in list view behaviour fails, and so focus isn't kept within the list view.
With this PR, we now always render the last item in the list, so in this test we now (correctly) have focus redirected to the inserted block within the list view, which is the expected behaviour.
I believe how that's all working now, but I've only done a light investigation.
I've switched it back to "ready for review". I've added an explanation to the updated e2e test — TL;DR, I believe this PR now fixes a bug with the insert before keyboard shortcut where sometimes the focus wouldn't be redirected back into the list view as expected. |
Should this be backported for WP 6.6? If so, please add the |
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 works pretty well. For me when testing, the windowing logic is a little bit slow to update, definitely much slower than shown in the after video of the PR description:
Kapture.2024-06-12.at.11.55.11.mp4
That's with around 500 blocks (the demo post with all blocks duplicated a few times).
I wonder if there's anything that can be done to show something visual for any placeholder that's on screen. One of those grey blocky things. It could be a separate PR, no need to block this one.
Thanks for reviewing @talldan! My test post only had 181 blocks in it, so I imagine the difference between our test posts is a contributing factor in the slowness there.
Another option I was wondering about could be to fade the list view items in one at a time when they render for real, instead of attempting to render them all at once. That way perhaps the rendering could be staggered and look a bit more natural? In any case, something to explore separately I reckon. I'll merge this in and we can have a play with follow-up ideas separately 👍 |
48968cd
to
33c501b
Compare
…ss#62312) * List View: Fix home and end key behaviour in very long lists * Update e2e test Co-authored-by: andrewserong <andrewserong@git.wordpress.org> Co-authored-by: talldan <talldanwp@git.wordpress.org> Co-authored-by: ellatrix <ellatrix@git.wordpress.org>
* List View: Fix home and end key behaviour in very long lists * Update e2e test Co-authored-by: andrewserong <andrewserong@git.wordpress.org> Co-authored-by: talldan <talldanwp@git.wordpress.org> Co-authored-by: ellatrix <ellatrix@git.wordpress.org>
* List View: Fix home and end key behaviour in very long lists * Update e2e test Co-authored-by: andrewserong <andrewserong@git.wordpress.org> Co-authored-by: talldan <talldanwp@git.wordpress.org> Co-authored-by: ellatrix <ellatrix@git.wordpress.org>
I just cherry-picked this PR to the wp/6.6-beta-3 branch to get it included in the next release: a12600f |
* List View: Fix home and end key behaviour in very long lists * Update e2e test Co-authored-by: andrewserong <andrewserong@git.wordpress.org> Co-authored-by: talldan <talldanwp@git.wordpress.org> Co-authored-by: ellatrix <ellatrix@git.wordpress.org>
What?
Part of #49563
Ensure that in very long lists, where the list view items are windowed (only rendered if they're visible) that the Home and End keys take the user to the very beginning or end of the list.
Why?
In very long documents or templates, the windowing logic in the list view takes effect which means that only visible items in the list view are rendered. This means that when you press Home or End to go up or down the list, the logic that determines which item to focus finds the end of the visible list instead of the end of the block tree. As a result, on
trunk
when you press End, you don't go to the end of the list, but instead only to the end of the current visible window.The proposed fix is to always render the first and last items of the list, so that there are focusable items for the Home and End keys to go to. This way it's possible to immediately go to the very beginning or end of the list.
Note: Page Up and Page Down keys are not yet supported in the list view. I'm exploring that separately over in #61474, though I'm unsure how much time I'll have to advance that one in the short-term.
How?
In the list view's logic where it determines whether to render the current list view item as a "real" item, always render if it's the first or last item in the list.
Testing Instructions
In a document with a very large number of blocks (e.g. > 100 blocks), open the list view, and then click a block in the list view twice to make sure that focus is within the list view.
Press Home and End keys on your keyboard. Notice that on
trunk
the Home and End keys don't always take you to the beginning or end of the document. With this PR applied, it should always take you to the beginning or end.For a quick way to add a large number of blocks, I like to copy + paste text from a book in the public domain. E.g. here's a copy of Dracula.
Screenshots or screencast
Before
2024-06-05.15.04.17.mp4
After
2024-06-05.15.06.17.mp4