Skip to content
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

Support both horizontal and vertical in-between inserters #27860

Merged
merged 11 commits into from
Jan 19, 2021

Conversation

youknowriad
Copy link
Contributor

@youknowriad youknowriad commented Dec 22, 2020

This is a bit fragile as it's a bit of a hacky code on top of the existing code which was also a bit hacky.

There are two parts that are fragile:

1- Compute the currently hovered insertion point: This is based on a global mouse move event and the issue is globally we don't know whether the parent is vertical or horizontal forcing us to do some hacks.
2- Once we know that an inserter need to be shown, positionning it properly is very hacky as well. Previously, it was using the block element as anchorRect of a Popover component and playing with the "position" (before or after the anchor). This approach don't work for horizontal popovers (positionning API is not good enough) so I've used getAnchorRect instead and I compute the position. The issue is that the popover doesn't update the position at the right time, for instance when I insert a block, you'll notice that the position don't change instantly.

Anyway, this kind of works, and might be polished but I wonder if we need to find a better way. This InsertionPointPopover seems very fragile to me. cc @ellatrix @talldan

Also, you'll notice that the insertion point is not centered properly between two blocks, the issue is that we don't really know the "margin" of the anchor to compute the position precisely.

Testing instructions

  • Try putting the mouse between two columns or two buttons...

@youknowriad youknowriad self-assigned this Dec 22, 2020
@youknowriad youknowriad added the Needs Design Feedback Needs general design feedback. label Dec 22, 2020
@github-actions
Copy link

github-actions bot commented Dec 22, 2020

Size Change: +774 B (0%)

Total Size: 1.28 MB

Filename Size Change
build/block-editor/index.js 122 kB +359 B (0%)
build/block-editor/style-rtl.css 11.9 kB +12 B (0%)
build/block-editor/style.css 11.9 kB +12 B (0%)
build/block-library/blocks/template-part/editor-rtl.css 794 B +80 B (+11%) ⚠️
build/block-library/blocks/template-part/editor.css 794 B +80 B (+11%) ⚠️
build/block-library/editor-rtl.css 9.06 kB +49 B (+1%)
build/block-library/editor.css 9.06 kB +49 B (+1%)
build/block-library/index.js 142 kB +136 B (0%)
build/components/index.js 173 kB -3 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.8 kB 0 B
build/api-fetch/index.js 3.42 kB 0 B
build/autop/index.js 2.84 kB 0 B
build/blob/index.js 665 B 0 B
build/block-directory/index.js 9.08 kB 0 B
build/block-directory/style-rtl.css 1.01 kB 0 B
build/block-directory/style.css 1.01 kB 0 B
build/block-library/blocks/archives/editor-rtl.css 196 B 0 B
build/block-library/blocks/archives/editor.css 196 B 0 B
build/block-library/blocks/audio/editor-rtl.css 194 B 0 B
build/block-library/blocks/audio/editor.css 194 B 0 B
build/block-library/blocks/audio/style-rtl.css 225 B 0 B
build/block-library/blocks/audio/style.css 225 B 0 B
build/block-library/blocks/block/editor-rtl.css 283 B 0 B
build/block-library/blocks/block/editor.css 283 B 0 B
build/block-library/blocks/button/editor-rtl.css 576 B 0 B
build/block-library/blocks/button/editor.css 577 B 0 B
build/block-library/blocks/button/style-rtl.css 552 B 0 B
build/block-library/blocks/button/style.css 552 B 0 B
build/block-library/blocks/buttons/editor-rtl.css 345 B 0 B
build/block-library/blocks/buttons/editor.css 346 B 0 B
build/block-library/blocks/buttons/style-rtl.css 419 B 0 B
build/block-library/blocks/buttons/style.css 419 B 0 B
build/block-library/blocks/calendar/style-rtl.css 319 B 0 B
build/block-library/blocks/calendar/style.css 319 B 0 B
build/block-library/blocks/categories/editor-rtl.css 210 B 0 B
build/block-library/blocks/categories/editor.css 209 B 0 B
build/block-library/blocks/categories/style-rtl.css 208 B 0 B
build/block-library/blocks/categories/style.css 208 B 0 B
build/block-library/blocks/code/style-rtl.css 216 B 0 B
build/block-library/blocks/code/style.css 216 B 0 B
build/block-library/blocks/columns/editor-rtl.css 300 B 0 B
build/block-library/blocks/columns/editor.css 299 B 0 B
build/block-library/blocks/columns/style-rtl.css 529 B 0 B
build/block-library/blocks/columns/style.css 528 B 0 B
build/block-library/blocks/cover/editor-rtl.css 524 B 0 B
build/block-library/blocks/cover/editor.css 522 B 0 B
build/block-library/blocks/cover/style-rtl.css 1.3 kB 0 B
build/block-library/blocks/cover/style.css 1.3 kB 0 B
build/block-library/blocks/embed/editor-rtl.css 594 B 0 B
build/block-library/blocks/embed/editor.css 595 B 0 B
build/block-library/blocks/embed/style-rtl.css 489 B 0 B
build/block-library/blocks/embed/style.css 489 B 0 B
build/block-library/blocks/file/editor-rtl.css 314 B 0 B
build/block-library/blocks/file/editor.css 313 B 0 B
build/block-library/blocks/file/style-rtl.css 352 B 0 B
build/block-library/blocks/file/style.css 352 B 0 B
build/block-library/blocks/freeform/editor-rtl.css 2.55 kB 0 B
build/block-library/blocks/freeform/editor.css 2.55 kB 0 B
build/block-library/blocks/gallery/editor-rtl.css 783 B 0 B
build/block-library/blocks/gallery/editor.css 783 B 0 B
build/block-library/blocks/gallery/style-rtl.css 1.17 kB 0 B
build/block-library/blocks/gallery/style.css 1.17 kB 0 B
build/block-library/blocks/group/editor-rtl.css 433 B 0 B
build/block-library/blocks/group/editor.css 432 B 0 B
build/block-library/blocks/group/style-rtl.css 190 B 0 B
build/block-library/blocks/group/style.css 190 B 0 B
build/block-library/blocks/heading/editor-rtl.css 248 B 0 B
build/block-library/blocks/heading/editor.css 248 B 0 B
build/block-library/blocks/heading/style-rtl.css 212 B 0 B
build/block-library/blocks/heading/style.css 212 B 0 B
build/block-library/blocks/html/editor-rtl.css 384 B 0 B
build/block-library/blocks/html/editor.css 385 B 0 B
build/block-library/blocks/image/editor-rtl.css 801 B 0 B
build/block-library/blocks/image/editor.css 800 B 0 B
build/block-library/blocks/image/style-rtl.css 569 B 0 B
build/block-library/blocks/image/style.css 570 B 0 B
build/block-library/blocks/latest-comments/editor-rtl.css 277 B 0 B
build/block-library/blocks/latest-comments/editor.css 275 B 0 B
build/block-library/blocks/latest-comments/style-rtl.css 382 B 0 B
build/block-library/blocks/latest-comments/style.css 382 B 0 B
build/block-library/blocks/latest-posts/editor-rtl.css 254 B 0 B
build/block-library/blocks/latest-posts/editor.css 254 B 0 B
build/block-library/blocks/latest-posts/style-rtl.css 634 B 0 B
build/block-library/blocks/latest-posts/style.css 634 B 0 B
build/block-library/blocks/list/editor-rtl.css 203 B 0 B
build/block-library/blocks/list/editor.css 203 B 0 B
build/block-library/blocks/list/style-rtl.css 201 B 0 B
build/block-library/blocks/list/style.css 201 B 0 B
build/block-library/blocks/media-text/editor-rtl.css 311 B 0 B
build/block-library/blocks/media-text/editor.css 311 B 0 B
build/block-library/blocks/media-text/style-rtl.css 642 B 0 B
build/block-library/blocks/media-text/style.css 640 B 0 B
build/block-library/blocks/more/editor-rtl.css 545 B 0 B
build/block-library/blocks/more/editor.css 545 B 0 B
build/block-library/blocks/navigation-link/editor-rtl.css 503 B 0 B
build/block-library/blocks/navigation-link/editor.css 504 B 0 B
build/block-library/blocks/navigation-link/style-rtl.css 805 B 0 B
build/block-library/blocks/navigation-link/style.css 803 B 0 B
build/block-library/blocks/navigation/editor-rtl.css 1.49 kB 0 B
build/block-library/blocks/navigation/editor.css 1.48 kB 0 B
build/block-library/blocks/navigation/style-rtl.css 289 B 0 B
build/block-library/blocks/navigation/style.css 289 B 0 B
build/block-library/blocks/nextpage/editor-rtl.css 507 B 0 B
build/block-library/blocks/nextpage/editor.css 507 B 0 B
build/block-library/blocks/paragraph/editor-rtl.css 236 B 0 B
build/block-library/blocks/paragraph/editor.css 236 B 0 B
build/block-library/blocks/paragraph/style-rtl.css 392 B 0 B
build/block-library/blocks/paragraph/style.css 392 B 0 B
build/block-library/blocks/post-author/editor-rtl.css 329 B 0 B
build/block-library/blocks/post-author/editor.css 329 B 0 B
build/block-library/blocks/post-author/style-rtl.css 303 B 0 B
build/block-library/blocks/post-author/style.css 303 B 0 B
build/block-library/blocks/post-comments-form/style-rtl.css 358 B 0 B
build/block-library/blocks/post-comments-form/style.css 358 B 0 B
build/block-library/blocks/post-content/editor-rtl.css 262 B 0 B
build/block-library/blocks/post-content/editor.css 262 B 0 B
build/block-library/blocks/post-excerpt/editor-rtl.css 206 B 0 B
build/block-library/blocks/post-excerpt/editor.css 206 B 0 B
build/block-library/blocks/post-featured-image/editor-rtl.css 453 B 0 B
build/block-library/blocks/post-featured-image/editor.css 453 B 0 B
build/block-library/blocks/post-featured-image/style-rtl.css 223 B 0 B
build/block-library/blocks/post-featured-image/style.css 223 B 0 B
build/block-library/blocks/preformatted/style-rtl.css 193 B 0 B
build/block-library/blocks/preformatted/style.css 193 B 0 B
build/block-library/blocks/pullquote/editor-rtl.css 304 B 0 B
build/block-library/blocks/pullquote/editor.css 304 B 0 B
build/block-library/blocks/pullquote/style-rtl.css 428 B 0 B
build/block-library/blocks/pullquote/style.css 428 B 0 B
build/block-library/blocks/query-loop/editor-rtl.css 217 B 0 B
build/block-library/blocks/query-loop/editor.css 216 B 0 B
build/block-library/blocks/query-loop/style-rtl.css 427 B 0 B
build/block-library/blocks/query-loop/style.css 429 B 0 B
build/block-library/blocks/query/editor-rtl.css 279 B 0 B
build/block-library/blocks/query/editor.css 279 B 0 B
build/block-library/blocks/quote/editor-rtl.css 195 B 0 B
build/block-library/blocks/quote/editor.css 195 B 0 B
build/block-library/blocks/quote/style-rtl.css 284 B 0 B
build/block-library/blocks/quote/style.css 285 B 0 B
build/block-library/blocks/rss/editor-rtl.css 307 B 0 B
build/block-library/blocks/rss/editor.css 309 B 0 B
build/block-library/blocks/rss/style-rtl.css 394 B 0 B
build/block-library/blocks/rss/style.css 393 B 0 B
build/block-library/blocks/search/editor-rtl.css 285 B 0 B
build/block-library/blocks/search/editor.css 285 B 0 B
build/block-library/blocks/search/style-rtl.css 454 B 0 B
build/block-library/blocks/search/style.css 456 B 0 B
build/block-library/blocks/separator/editor-rtl.css 229 B 0 B
build/block-library/blocks/separator/editor.css 229 B 0 B
build/block-library/blocks/separator/style-rtl.css 352 B 0 B
build/block-library/blocks/separator/style.css 352 B 0 B
build/block-library/blocks/shortcode/editor-rtl.css 603 B 0 B
build/block-library/blocks/shortcode/editor.css 603 B 0 B
build/block-library/blocks/site-logo/editor-rtl.css 321 B 0 B
build/block-library/blocks/site-logo/editor.css 321 B 0 B
build/block-library/blocks/site-logo/style-rtl.css 238 B 0 B
build/block-library/blocks/site-logo/style.css 238 B 0 B
build/block-library/blocks/social-link/editor-rtl.css 283 B 0 B
build/block-library/blocks/social-link/editor.css 283 B 0 B
build/block-library/blocks/social-links/editor-rtl.css 811 B 0 B
build/block-library/blocks/social-links/editor.css 810 B 0 B
build/block-library/blocks/social-links/style-rtl.css 1.48 kB 0 B
build/block-library/blocks/social-links/style.css 1.48 kB 0 B
build/block-library/blocks/spacer/editor-rtl.css 416 B 0 B
build/block-library/blocks/spacer/editor.css 416 B 0 B
build/block-library/blocks/spacer/style-rtl.css 184 B 0 B
build/block-library/blocks/spacer/style.css 184 B 0 B
build/block-library/blocks/subhead/editor-rtl.css 223 B 0 B
build/block-library/blocks/subhead/editor.css 223 B 0 B
build/block-library/blocks/subhead/style-rtl.css 210 B 0 B
build/block-library/blocks/subhead/style.css 210 B 0 B
build/block-library/blocks/table/editor-rtl.css 593 B 0 B
build/block-library/blocks/table/editor.css 593 B 0 B
build/block-library/blocks/table/style-rtl.css 501 B 0 B
build/block-library/blocks/table/style.css 501 B 0 B
build/block-library/blocks/tag-cloud/editor-rtl.css 237 B 0 B
build/block-library/blocks/tag-cloud/editor.css 235 B 0 B
build/block-library/blocks/tag-cloud/style-rtl.css 221 B 0 B
build/block-library/blocks/tag-cloud/style.css 221 B 0 B
build/block-library/blocks/text-columns/editor-rtl.css 220 B 0 B
build/block-library/blocks/text-columns/editor.css 220 B 0 B
build/block-library/blocks/text-columns/style-rtl.css 283 B 0 B
build/block-library/blocks/text-columns/style.css 283 B 0 B
build/block-library/blocks/verse/editor-rtl.css 194 B 0 B
build/block-library/blocks/verse/editor.css 194 B 0 B
build/block-library/blocks/verse/style-rtl.css 215 B 0 B
build/block-library/blocks/verse/style.css 215 B 0 B
build/block-library/blocks/video/editor-rtl.css 617 B 0 B
build/block-library/blocks/video/editor.css 617 B 0 B
build/block-library/blocks/video/style-rtl.css 303 B 0 B
build/block-library/blocks/video/style.css 304 B 0 B
build/block-library/common-rtl.css 1.01 kB 0 B
build/block-library/common.css 1.01 kB 0 B
build/block-library/style-rtl.css 8.59 kB 0 B
build/block-library/style.css 8.59 kB 0 B
build/block-library/theme-rtl.css 860 B 0 B
build/block-library/theme.css 860 B 0 B
build/block-serialization-default-parser/index.js 1.88 kB 0 B
build/block-serialization-spec-parser/index.js 3.06 kB 0 B
build/blocks/index.js 48.1 kB 0 B
build/components/style-rtl.css 15.5 kB 0 B
build/components/style.css 15.5 kB 0 B
build/compose/index.js 11.3 kB 0 B
build/core-data/index.js 15.2 kB 0 B
build/data-controls/index.js 829 B 0 B
build/data/index.js 8.99 kB 0 B
build/date/index.js 31.8 kB 0 B
build/deprecated/index.js 769 B 0 B
build/dom-ready/index.js 571 B 0 B
build/dom/index.js 4.95 kB 0 B
build/edit-navigation/index.js 11.2 kB 0 B
build/edit-navigation/style-rtl.css 938 B 0 B
build/edit-navigation/style.css 944 B 0 B
build/edit-post/index.js 306 kB 0 B
build/edit-post/style-rtl.css 6.51 kB 0 B
build/edit-post/style.css 6.5 kB 0 B
build/edit-site/index.js 24.2 kB 0 B
build/edit-site/style-rtl.css 4.01 kB 0 B
build/edit-site/style.css 4.01 kB 0 B
build/edit-widgets/index.js 23.6 kB 0 B
build/edit-widgets/style-rtl.css 3.17 kB 0 B
build/edit-widgets/style.css 3.17 kB 0 B
build/editor/editor-styles-rtl.css 543 B 0 B
build/editor/editor-styles.css 545 B 0 B
build/editor/index.js 41.9 kB 0 B
build/editor/style-rtl.css 3.89 kB 0 B
build/editor/style.css 3.89 kB 0 B
build/element/index.js 4.62 kB 0 B
build/escape-html/index.js 735 B 0 B
build/format-library/index.js 6.76 kB 0 B
build/format-library/style-rtl.css 620 B 0 B
build/format-library/style.css 621 B 0 B
build/hooks/index.js 2.27 kB 0 B
build/html-entities/index.js 623 B 0 B
build/i18n/index.js 3.57 kB 0 B
build/is-shallow-equal/index.js 697 B 0 B
build/keyboard-shortcuts/index.js 2.54 kB 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/index.js 3.15 kB 0 B
build/list-reusable-blocks/style-rtl.css 629 B 0 B
build/list-reusable-blocks/style.css 628 B 0 B
build/media-utils/index.js 5.32 kB 0 B
build/notices/index.js 1.85 kB 0 B
build/nux/index.js 3.42 kB 0 B
build/nux/style-rtl.css 731 B 0 B
build/nux/style.css 727 B 0 B
build/plugins/index.js 2.54 kB 0 B
build/primitives/index.js 1.43 kB 0 B
build/priority-queue/index.js 790 B 0 B
build/redux-routine/index.js 2.84 kB 0 B
build/reusable-blocks/index.js 2.92 kB 0 B
build/rich-text/index.js 13.5 kB 0 B
build/server-side-render/index.js 2.77 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.27 kB 0 B
build/url/index.js 3.02 kB 0 B
build/viewport/index.js 1.86 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.22 kB 0 B

compressed-size-action

Base automatically changed from show/insertion-point-indicator-in-between to master December 30, 2020 09:23
@jasmussen
Copy link
Contributor

This is cool!

I'm testing in TwentyTwentyOne Blocks and seeing some issues around how the buttons are spaced, this appears to be a separate issue, but it does affect the positioning of the sibling inserter:

screencast 2021-01-04 12-43-04

In this branch the sibling inserter is also not perfectly centered between blocks, in the horizontal version. Those are some things we'll probably want to hammer out to get this shipping, but in principle, this seems fine! Anything in specific you'd like input on?

@youknowriad
Copy link
Contributor Author

Yes, I'm not sure exactly how to solve the positionning issue when the position is supposed to change (after inserting a button for instance, you'll notice a jump). I'd like some input from @ellatrix here on how you think we should deal with the Popover position properly.

And yes, you notice that it's not centered properly neither horizontally or vertically between two adjacent blocks, the reason is "margins". Margins between blocks are random values defined by the CSS of the theme and it's not something we can easily include in the computation of the position of the in-between inserter. It seems the current approach was just relying on the default top/bottom margin values.

@jasmussen
Copy link
Contributor

Yep. Margins and space-between properties make this one tricky, I can definitely see it.

Outside of being able to calculate the space between blocks, sans margins or space-between shenanigans, I'd be open to creative solutions.

@youknowriad youknowriad force-pushed the try/vertical-inbetween-inserter branch 2 times, most recently from d0dcf85 to e9423ab Compare January 5, 2021 10:09
@youknowriad
Copy link
Contributor Author

I pushed some tweaks to center the insertion point properly in both directions (by dynamically getting the position of the previous block). There's still some funkiness when clicking the inserter though.

@shaunandrews
Copy link
Contributor

This works great when I just hover — I see the insertion guide and + button and it all lines up as expected for both horizontally and vertically orientated containers.

But once I add a block, the insertion guide remains. Here's what it looks like when I try to add a new Column:

Adding a Column

The newly added column doesn't have a width set, so it's a little funky to actually use; It would be nice to give it a defined width and adjust the others accordingly.

After adding the new Column the in-between inserter no longer works anywhere and gets stuck. I can recreate a similar behavior when adding a new Button in-between two existing buttons.

@youknowriad youknowriad force-pushed the try/vertical-inbetween-inserter branch from e9423ab to 7640ad4 Compare January 14, 2021 08:51
@youknowriad
Copy link
Contributor Author

Made an update here, I think this is getting very close.

@youknowriad
Copy link
Contributor Author

(The columns width thing is something we should explore separately, it's not specific to the in between inserter, you can have the same result with the default inserter)

@shaunandrews
Copy link
Contributor

Working great with Columns and Buttons, but I can't seem to trigger the in-between inserter within the Navigation block.

@youknowriad
Copy link
Contributor Author

@shaunandrews there are actually two bugs preventing the in-between inserter to trigger in the navigation block:

  • A logic bug (media&text was broken too because of this) that is fixed in 8c6d51d
  • A style bug: The in-between inserter only shows up if there's a margin between two adjacent blocks. In the case of the navigation menu, there is none, it's a padding. Changing the behavior here would be impactful: won't be able to actually click the block to select (since the padding is part of the block), so I'm not sure we should change that. A potential solution would be to actually use margins between the navigation elements (but this is separate from this PR)

Copy link
Contributor

@talldan talldan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@youknowriad Apologies it took so long to review. I know @ellatrix made some changes in #27537 to make the insertion point show vertically for drag and drop. But the changes here seem good, and I'm sure can work with the changes in that PR. I left a couple of questions that might need to be resolved.

In testing this is working well for me. I noticed that because the height of blocks when shown horizontally tends to be much less than the width for vertical blocks, things can get a bit cramped:
Screenshot 2021-01-18 at 11 10 17 am

Not a blocker, I'm sure it can be iterated on over time.

Comment on lines +61 to +70
const targetRootClientId = clientId
? getBlockRootClientId( clientId )
: rootClientId;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering why the logic wasn't something like:

const targetRootClientId = rootClientId ? rootClientId : getBlockRootClientId( clientId );

I'm sure there's a good reason, but might be worth leaving a comment for others reading the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has to do with the fact that this is both used for the insertion point when the inserter is opened (use the insertion poin t from there) and the hovered insertion point.

@talldan talldan added [Feature] Inserter The main way to insert blocks using the + button in the editing interface [Type] Enhancement A suggestion for improvement. labels Jan 18, 2021
@jasmussen
Copy link
Contributor

In testing this is working well for me. I noticed that because the height of blocks when shown horizontally tends to be much less than the width for vertical blocks, things can get a bit cramped:

I just tested this again, because the screenshot looked a bit concerning. But after having tried it, yes, I'd agree this can be iterated — the important part is that the sibling inserter doesn't cover each block, you have to actually hover the pixels between the blocks. That's still a little fiddly, but it's better than the sibling inserter being too easy to invoke in such a small space, and still just something to look at.

@youknowriad
Copy link
Contributor Author

Thanks for the review @talldan both points were actual bugs that should be fixed now.

@youknowriad youknowriad force-pushed the try/vertical-inbetween-inserter branch from f786a20 to a7d4127 Compare January 18, 2021 14:44
Copy link
Contributor

@talldan talldan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@youknowriad youknowriad force-pushed the try/vertical-inbetween-inserter branch from 5e2bf71 to c9f8abe Compare January 19, 2021 09:29
@youknowriad
Copy link
Contributor Author

@kevin940726 I rebased, I think something in this PR actually broke the test but I don't understand what yet.

@youknowriad
Copy link
Contributor Author

I think the issue with the widgets tests is that now we need the previous and next blocks to render the insertion point while previously we were doing it with just the previous node. This means the insertion point doesn't show up when it's the last in the canvas, maybe it's fine for now.

@youknowriad
Copy link
Contributor Author

Ok let's try this and see how it goes.

@youknowriad youknowriad merged commit dd80022 into master Jan 19, 2021
@youknowriad youknowriad deleted the try/vertical-inbetween-inserter branch January 19, 2021 17:48
@github-actions github-actions bot added this to the Gutenberg 9.9 milestone Jan 19, 2021
@kevin940726
Copy link
Member

Hmm, why is this fine? This seems like a bug to me 🤔 .

Don't we want to show a insertion point indicator when we're just hovering over a block in the global inserter?

@youknowriad
Copy link
Contributor Author

@kevin940726 I agree it's a good thing, though having the insertion point after the last element of the canvas, seemed less important than positioning the inserter properly between two adjacent blocks (basically this PR makes the next and previous mandatory to show the insertion point), I think it might be possible to have both but it may require some complexities in the code.

@kevin940726
Copy link
Member

@youknowriad If we agree that it should be supported, shouldn't we open a follow-up issue for that? Or is this already planned 😅?

@youknowriad
Copy link
Contributor Author

@kevin940726 Yes, good call, I tracked it here #28381

@jasmussen
Copy link
Contributor

I'm not completely sure, but I believe this PR may have caused #28827.

Comment on lines -59 to -68
const { ownerDocument } = containerRef.current;
const targetRect = target.getBoundingClientRect();
const isReverse = clientY < targetRect.top + targetRect.height / 2;
const blockNode = getBlockDOMNode( clientId, ownerDocument );
const container = isReverse ? containerRef.current : blockNode;
const closest =
getClosestTabbable( blockNode, true, container ) || blockNode;
const rect = new window.DOMRect( clientX, clientY, 0, 16 );

placeCaretAtVerticalEdge( closest, isReverse, rect, false );
Copy link
Contributor

@stokesman stokesman Feb 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we will want to bring this logic back though it probably needs adaptation for horizontal contexts. See #28682 (comment)

@@ -550,36 +550,6 @@ describe( 'Writing Flow', () => {
expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'should not have a dead zone between blocks (upper)', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove this behaviour?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's related to this #28682 (comment)

Basically, I just though that it doesn't make sense to focus the previous or the next block depending on a a small gap (the margin is very small) and just chose to focus the next one every time. Thought after discussing on that issue, I think focusing the end of the previous block or the start of the next block would be better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Inserter The main way to insert blocks using the + button in the editing interface Needs Design Feedback Needs general design feedback. [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants