Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion editor/modes/visual-editor/block-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class VisualEditorBlockList extends Component {
onSelectionStart={ this.onSelectionStart }
onShiftSelection={ this.onShiftSelection }
/>,
<VisualEditorSiblingInserter

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Because we are doing a flatmap, we could also just concat to the array of the block with either an empty array (when at last position), or an array containing this inserter. However, if you're happy with this && approach, then it should be fine.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can also simplify this code by removing the line before flatmap call and moving the Inserter to the first place in the array, in effect always prepend to the existing block.

@ephox-mogran ephox-mogran Nov 15, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

True. That's probably better. Is there any reason that the SiblingInserter isn't added when the default "Write Your Story" block is there?

@gziolo gziolo Nov 15, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It looks like the Write Your Story block isn't a real block but only a placeholder.

Yes, I can confirm this. I inspected Redux state. When you click on Write Your Story, a new block is created for you.

index < blocks.length - 1 && <VisualEditorSiblingInserter

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Lack of parentheses make this a bit ambiguous (similar to no-mixed-operators). Is < considered before or after the subtraction (index < blocks.length)? Is subtraction including the element (1 && <VisualEditorSiblingInserter)?

Maybe:

index < ( blocks-length - 1 ) && (
	<VisualEditorSiblingInserter

I have some similar thoughts here as in #3246 (review) between this approach and allowing the inserter component itself to consider whether it should render itself. Any thoughts? I don't feel strongly either way.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The other approach seems fine to me.

key={ 'sibling-inserter-' + uid }
insertIndex={ index + 1 }
/>,
Expand Down