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

Fix blue line indicator not showing at the end #25849

Merged
merged 6 commits into from
Oct 8, 2020

Conversation

kevin940726
Copy link
Member

@kevin940726 kevin940726 commented Oct 6, 2020

This PR is based on #25727 to make sure e2e passes. It should be rebased to master once #25727 merged.

Description

Fix #25785, related to #25727. Also fixes #25785 (comment).

Fix the blue line indicator is not showing at the end when using the global inserter to try to insert a block in a post or in a widget area.

This is more complicated than I thought, I couldn't think of any better way to do this, please feel free to give me some suggestions and guidance.

Internally, I use a AppenderContext to store a Map to keep the Appender's references. Then we can inject the blue line indicator alongside the appender, which usually lives at the end of the block list.

How has this been tested?

Run the e2e test, or...

  1. Go to Post editor, create a new post
  2. Click the global inserter, hover over the Heading block
  3. Observe the blue line indicator is showing at the end
  4. Create some blocks, observe that (2) and (3) still works
  5. Select any block in between
  6. Click the global inserter, hover over the Heading block
  7. Observe that the blue line indicator is showing in between blocks

The same steps can also be tested in the widget editor.

Screenshots

Post editor
Kapture 2020-10-06 at 11 17 15

Widget editor
Kapture 2020-10-06 at 11 18 32

Types of changes

Bug fix

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@kevin940726 kevin940726 added [Type] Bug An existing feature does not function as intended [Feature] Inserter The main way to insert blocks using the + button in the editing interface labels Oct 6, 2020
@github-actions
Copy link

github-actions bot commented Oct 6, 2020

Size Change: +139 B (0%)

Total Size: 1.18 MB

Filename Size Change
build/block-editor/index.js 129 kB +98 B (0%)
build/block-editor/style-rtl.css 11 kB +10 B (0%)
build/block-editor/style.css 11 kB +13 B (0%)
build/edit-widgets/index.js 21.4 kB +18 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.52 kB 0 B
build/api-fetch/index.js 3.35 kB 0 B
build/autop/index.js 2.72 kB 0 B
build/blob/index.js 668 B 0 B
build/block-directory/index.js 8.55 kB 0 B
build/block-directory/style-rtl.css 943 B 0 B
build/block-directory/style.css 942 B 0 B
build/block-library/editor-rtl.css 8.65 kB 0 B
build/block-library/editor.css 8.65 kB 0 B
build/block-library/index.js 135 kB 0 B
build/block-library/style-rtl.css 7.66 kB 0 B
build/block-library/style.css 7.65 kB 0 B
build/block-library/theme-rtl.css 741 B 0 B
build/block-library/theme.css 741 B 0 B
build/block-serialization-default-parser/index.js 1.78 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/blocks/index.js 47.5 kB 0 B
build/components/index.js 169 kB 0 B
build/components/style-rtl.css 15.3 kB 0 B
build/components/style.css 15.3 kB 0 B
build/compose/index.js 9.42 kB 0 B
build/core-data/index.js 12 kB 0 B
build/data-controls/index.js 685 B 0 B
build/data/index.js 8.6 kB 0 B
build/date/index.js 31.9 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 4.42 kB 0 B
build/edit-navigation/index.js 10.7 kB 0 B
build/edit-navigation/style-rtl.css 868 B 0 B
build/edit-navigation/style.css 871 B 0 B
build/edit-post/index.js 306 kB 0 B
build/edit-post/style-rtl.css 6.29 kB 0 B
build/edit-post/style.css 6.27 kB 0 B
build/edit-site/index.js 20.4 kB 0 B
build/edit-site/style-rtl.css 3.84 kB 0 B
build/edit-site/style.css 3.84 kB 0 B
build/edit-widgets/style-rtl.css 3 kB 0 B
build/edit-widgets/style.css 3 kB 0 B
build/editor/editor-styles-rtl.css 492 B 0 B
build/editor/editor-styles.css 493 B 0 B
build/editor/index.js 45.5 kB 0 B
build/editor/style-rtl.css 3.85 kB 0 B
build/editor/style.css 3.84 kB 0 B
build/element/index.js 4.44 kB 0 B
build/escape-html/index.js 734 B 0 B
build/format-library/index.js 7.49 kB 0 B
build/format-library/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/hooks/index.js 1.74 kB 0 B
build/html-entities/index.js 621 B 0 B
build/i18n/index.js 3.54 kB 0 B
build/is-shallow-equal/index.js 710 B 0 B
build/keyboard-shortcuts/index.js 2.39 kB 0 B
build/keycodes/index.js 1.85 kB 0 B
build/list-reusable-blocks/index.js 3.02 kB 0 B
build/list-reusable-blocks/style-rtl.css 476 B 0 B
build/list-reusable-blocks/style.css 476 B 0 B
build/media-utils/index.js 5.12 kB 0 B
build/notices/index.js 1.69 kB 0 B
build/nux/index.js 3.27 kB 0 B
build/nux/style-rtl.css 671 B 0 B
build/nux/style.css 668 B 0 B
build/plugins/index.js 2.44 kB 0 B
build/primitives/index.js 1.34 kB 0 B
build/priority-queue/index.js 790 B 0 B
build/redux-routine/index.js 2.85 kB 0 B
build/rich-text/index.js 13 kB 0 B
build/server-side-render/index.js 2.6 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.24 kB 0 B
build/url/index.js 4.06 kB 0 B
build/viewport/index.js 1.74 kB 0 B
build/warning/index.js 1.13 kB 0 B
build/wordcount/index.js 1.17 kB 0 B

compressed-size-action

Base automatically changed from update/fix-insertion-point-in-widgets-editor to master October 6, 2020 08:24
// Can't find the element, might be at the end of the block list, or inside an empty block list.
// We instead try to find the "Appender" and place the indicator above it.
// `rootClientId` could be null or undefined when there's no parent block, we normalize it to an empty string.
return appenderMap.get( rootClientId || '' );
Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking of some different approaches,getBlockDOMNode just does a getElementById call, could it be an option to do something similar for the appender using querySelector? e.g

document.querySelector( `#block-${ rootClientId } .block-list-appender` );

Copy link
Member Author

Choose a reason for hiding this comment

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

That's actually my first attempt. However, I just don't feel like it's "react"ive enough as we'll be relying on the DOM structure and classnames.

Copy link
Member

Choose a reason for hiding this comment

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

I think we should go for the simpler solution. We're doing the same for block nodes, and this should be revised together if we'd like to avoid querying the DOM.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not as simple as just a querySelector call though. Since clientId could be null, also could rootClientId. We have to add some more code to be able to select the parent of the appender.

@kevin940726 kevin940726 force-pushed the update/fix-insertion-blue-line-at-end branch from 219c7cf to c314041 Compare October 6, 2020 09:12
// Can't find the element, might be at the end of the block list, or inside an empty block list.
// We instead try to find the "Appender" and place the indicator above it.
// `rootClientId` could be null or undefined when there's no parent block, we normalize it to an empty string.
return appenderNodesMap.get( rootClientId || '' );
Copy link
Member

Choose a reason for hiding this comment

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

The insertion point is added at the root of the whole tree of blocks, so I think rootClientId will always be '', never an id?

Copy link
Member

Choose a reason for hiding this comment

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

In other words, does the indicator work for nested appenders?

Copy link
Member Author

Choose a reason for hiding this comment

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

It could be an id if it's in the Widget Editor though, widget-area is kind of like a special case for this 😜.

Also, <InsertionPoint> only handles getting of the appender nodes. <BlockList> is where setting happens, which can be in <InnerBlocks> or widget-area. What I'm trying to say here is that a <InsertionPoint> could have multiple <BlockList> hence could also have multiple <BlockListAppender>.

Copy link
Member Author

Choose a reason for hiding this comment

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

In other words, does the indicator work for nested appenders?

It should, at least for my testing below.

image

@paaljoachim
Copy link
Contributor

paaljoachim commented Oct 6, 2020

From what I am seeing in the Post Editor. Creating a new post, adding a heading and adding a paragraph block. Having the second to last block active when clicking the Inserter and hovering over a block will show a line below the second to last block. IF I have the last block active no blue line will be seen below that.

The second to last block is selected. One sees the blue line below.
Screen Shot 2020-10-06 at 11 48 06

The last block is selected. One can not see the blue line below the text.
Screen Shot 2020-10-06 at 11 48 36


Widget screen.

Current 9.1. Which has the blue line error.
Screen Shot 2020-10-06 at 11 52 49

This PR.
I added a Heading block then clicked the Inserter and hovered over a block.
(For whatever reason Line Height control in Heading is not seen in this PR but is seen in 9.1)
Screen Shot 2020-10-06 at 11 54 50

Another test. Having Footer 2 open. Closing footer 1.
Screen Shot 2020-10-06 at 11 57 44

From what I see the blue line only shows up if the first widget area is open. Closing the first widget area and having in this example Footer 2 open will not show a blue line in the top of footer 2.

@kevin940726
Copy link
Member Author

@paaljoachim I can't seem to reproduce those 🙀, see my screenshots/GIFs in the PR description above.

Closing the first widget area and having in this example Footer 2 open will not show a blue line in the top of footer 2.

The blue line should be at the bottom of the footer 2 though. See #25708 for more info. It's likely that the blue line is at the bottom of the widgets and since the viewport doesn't auto-scroll to it it's not visible.

@paaljoachim
Copy link
Contributor

@kevin940726 Kevin
Then it is on my end as I am lately getting npm run build errors. Making it very difficult for me to test PR's. As some seems to work while others not.

Copy link
Contributor

@draganescu draganescu left a comment

Choose a reason for hiding this comment

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

In my testing this behaved as expected.

@draganescu draganescu merged commit e376eab into master Oct 8, 2020
@draganescu draganescu deleted the update/fix-insertion-blue-line-at-end branch October 8, 2020 11:51
draganescu added a commit that referenced this pull request Oct 8, 2020
@github-actions github-actions bot added this to the Gutenberg 9.2 milestone Oct 8, 2020
@draganescu
Copy link
Contributor

@ellatrix I got a bit trigger happy :) if you have objections to merging this we can revert!

@ellatrix
Copy link
Member

ellatrix commented Oct 8, 2020

It's ok, we can adjust it later.

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 [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Block insertertion point blue line isn't visible when inserting at end of block list
5 participants