-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
adds selection persistence on sidebar tab switch #15583
Conversation
@gziolo using the page.$ selection engine from puppeteer I couldn't get 'is-selected' no matter what I did, hence the eval solution in the test. Not sure why, but the selector was always null, even though visual inspection contradicted that. The state update in this PR is generic enough, the only required implementation is to dispatch the new action whenever we want to return the previous selection after clearing. |
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.
The state update in this PR is generic enough, the only required implementation is to dispatch the new action whenever we want to return the previous selection after clearing.
Yes, it looks very clean in the current shape. I like this proposal 👍
There is some more work required on this branch as noted in code comments. Travis isn't happy about the following as well:
- There are failing unit tests with these changes applied:
https://travis-ci.com/WordPress/gutenberg/jobs/199430106#L5455
I think it's expected that there are going to be actions where the previous selection will have to be cleared as well.
-
There are new public API methods added so you will have to run
npm run docs:build
to refresh docs. -
There is one e2e test failing which looks completely unrelated:
https://travis-ci.com/WordPress/gutenberg/jobs/199430115#L1092
FAIL packages/e2e-tests/specs/editor-modes.test.js (11.732s)
● Editing modes (visual/HTML) › the code editor should unselect blocks and disable the inserter
expect(received).not.toBeNull()
Received: null
112 | await page.click( '.edit-post-sidebar__panel-tab[data-label="Block"]' );
113 | const noBlocksElement = await page.$( '.block-editor-block-inspector__no-blocks' );
> 114 | expect( noBlocksElement ).not.toBeNull();
| ^
115 |
116 | // The inserter is disabled
117 | const disabledInserter = await page.$( '.block-editor-inserter > button:disabled' );
at toBeNull (specs/editor-modes.test.js:114:33)
at tryCatch (../../node_modules/regenerator-runtime/runtime.js:45:40)
at Generator.invoke [as _invoke] (../../node_modules/regenerator-runtime/runtime.js:271:22)
at Generator.prototype.(anonymous function) [as next] (../../node_modules/regenerator-runtime/runtime.js:97:21)
at asyncGeneratorStep (specs/editor-modes.test.js:11:103)
at _next (specs/editor-modes.test.js:13:194)
c59ea0b
to
9e43f15
Compare
fixed two tests, made a new one fail! yay! :) |
2cb2c40
to
79f22e0
Compare
I had to add a way to clear previousSelection destructively, that is without saving previous selection, so that restoreBlock wouldn't find anything to restore when invoked. The case was needed when selecting text mode, and called restoreBlock it looked in the UI as if there were some blocks selected, even though none existed. |
we should wipe the selection when the blocks are intentionally unselected and write a test about that. |
I have added a wipeBlockSelection as a way to destructively clear block selection and called it on visual/text editor mode switch and also when all blocks are manually deselected. |
5709b2f
to
4b1becd
Compare
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.
I will retest later today, code wise it looks good 👍
…le and manual deselection
bc2f4ad
to
050685d
Compare
@gziolo everything should be up to date and conform to the requested changes :) |
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.
Thank you for addressing this issue. This is a really great improvement! Code looks great 💯
Coming to this late, but a few brief observations in passing:
|
oh boy :) so many things. First the decision to deselect blocks when using the document inspector is an older design decision a while ago . Second, I had no idea about Indeed, clear vs wipe, maybe it's not the best :) Naming is hard. Initially I wanted to pass an object as an argument to I will create an issue for the error on |
Thanks for sharing the context. I hadn't seen @jasmussen 's comment. It helps frame this pair of tabs as something of being mutually exclusive to there being / not being a selection of blocks, which I wasn't aware of. Aside from this point, one of the motivators in my prior comment is in limiting what we add to our own maintenance burden if existing concepts could apply.
I noticed after making my comment that @afercia had commented similarly at #13309 (comment) . Since this issue has been reopened, it may be enough to use that one for tracking? I thought we did have |
Currently you can customize the document loaded, and you can customize each block in that document. One of the things that may be explored in the future, is to allow you to customize also the site itself (i.e. Site | Document | Block) as tabs. The argument made in the past, and thanks for considering it, is that by leveraging breadcrumbs instead of tabs, we make the hierarchy clear (Site → Document → Block). It also has the benefit that breadcrumbs can help you indicate this hierarchy even further (Site → Document → Columns → Column → Quote → Paragraph), and finally that both in cases of translation length and for the longer breadcrumb, it can wrap to two lines, whereas tabs can't. But at the same time, it is critical to such breadcrumbs that they are directly tied to what is selected. If you have a block selected and click the "Site" breadcrumb, that's what should get selected. |
Based on the fact that there are some technical uncertainties and that the original issue is not really fixed by that PR, I'm wondering if we should revert this for this release and give this more time to mature and address these concerns. |
Description
Fixes #13309
When a block is selected or multi selected switching the settings sidebar to document deselects everything but switching back to block selects everything back.
How has this been tested?
There is an e2e test in the a11y suite.
Screenshots
Types of changes
Non breaking changes.
Added a new action in the core/block-editor store, restoreSelectedBlock.
Updated the blockSelection reducer of the core/block-editor store.
Checklist: