-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Inserter: Fix the insertion point #994
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
Changes from all commits
ecbee44
1df84c7
2186d41
a2e90db
3d16e47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,6 @@ | |
| * External dependencies | ||
| */ | ||
| import { connect } from 'react-redux'; | ||
| import clickOutside from 'react-click-outside'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
|
|
@@ -56,10 +55,6 @@ class VisualEditorBlockList extends wp.element.Component { | |
| this.setState( { selectionAtStart: null } ); | ||
| } | ||
|
|
||
| handleClickOutside() { | ||
| this.props.clearSelectedBlock(); | ||
| } | ||
|
|
||
| render() { | ||
| const { blocks, insertionPoint } = this.props; | ||
| const insertionPointIndex = blocks.indexOf( insertionPoint ); | ||
|
|
@@ -106,9 +101,8 @@ export default connect( | |
| selectionEnd: getBlockSelectionEnd( state ), | ||
| } ), | ||
| ( dispatch ) => ( { | ||
| clearSelectedBlock: () => dispatch( { type: 'CLEAR_SELECTED_BLOCK' } ), | ||
| onMultiSelect( { start, end } ) { | ||
| dispatch( { type: 'MULTI_SELECT', start, end } ); | ||
| }, | ||
| } ) | ||
| )( clickOutside( VisualEditorBlockList ) ); | ||
|
||
| )( VisualEditorBlockList ); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,13 @@ | ||
| /** | ||
| * External dependencies | ||
| */ | ||
| import { connect } from 'react-redux'; | ||
|
|
||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { __ } from 'i18n'; | ||
| import { Component } from 'element'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
|
|
@@ -11,16 +17,48 @@ import Inserter from '../../inserter'; | |
| import VisualEditorBlockList from './block-list'; | ||
| import PostTitle from '../../post-title'; | ||
|
|
||
| export default function VisualEditor() { | ||
| return ( | ||
| <div | ||
| role="region" | ||
| aria-label={ __( 'Visual Editor' ) } | ||
| className="editor-visual-editor" | ||
| > | ||
| <PostTitle /> | ||
| <VisualEditorBlockList /> | ||
| <Inserter position="top right" /> | ||
| </div> | ||
| ); | ||
| class VisualEditor extends Component { | ||
| constructor() { | ||
| super( ...arguments ); | ||
| this.bindContainer = this.bindContainer.bind( this ); | ||
| this.onClick = this.onClick.bind( this ); | ||
| } | ||
|
|
||
| bindContainer( ref ) { | ||
| this.container = ref; | ||
| } | ||
|
|
||
| onClick( event ) { | ||
| if ( event.target === this.container ) { | ||
|
||
| this.props.clearSelectedBlock(); | ||
| } | ||
| } | ||
|
|
||
| render() { | ||
| // Disable reason: Clicking the canvas should clear the selection | ||
| /* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/onclick-has-role, jsx-a11y/click-events-have-key-events */ | ||
| return ( | ||
| <div | ||
| role="region" | ||
| aria-label={ __( 'Visual Editor' ) } | ||
| className="editor-visual-editor" | ||
| onClick={ this.onClick } | ||
| ref={ this.bindContainer } | ||
| > | ||
| <PostTitle /> | ||
| <VisualEditorBlockList /> | ||
| <Inserter position="top right" /> | ||
| </div> | ||
| ); | ||
| /* eslint-enable jsx-a11y/no-static-element-interactions, jsx-a11y/onclick-has-role, jsx-a11y/click-events-have-key-events */ | ||
| } | ||
| } | ||
|
|
||
| export default connect( | ||
| undefined, | ||
| ( dispatch ) => ( { | ||
| clearSelectedBlock() { | ||
| dispatch( { type: 'CLEAR_SELECTED_BLOCK' } ); | ||
| }, | ||
| } ) | ||
| )( VisualEditor ); | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
In a subsequent pull request, we should think about consolidating or simplifying some of this shared logic between the menu and the root component. I still think it's a bit bizarre how we assign insertion point in the hover intent, but IIRC the reasoning was to show the indicator in the post.
Uh oh!
There was an error while loading. Please reload this page.
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.
Yes, right! Actually, I thought about passing a prop from the
inserterto themenuto void recomputing.