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

Writing Flow: Remove onBottomReached handling #5271

Merged
merged 1 commit into from Feb 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 1 addition & 46 deletions editor/components/writing-flow/index.js
Expand Up @@ -3,7 +3,7 @@
*/
import { connect } from 'react-redux';
import 'element-closest';
import { find, last, reverse, get } from 'lodash';
import { find, reverse, get } from 'lodash';

/**
* WordPress dependencies
Expand All @@ -22,7 +22,6 @@ import {
/**
* Internal dependencies
*/
import { BlockListBlock } from '../block-list/block';
import {
getPreviousBlockUid,
getNextBlockUid,
Expand All @@ -32,7 +31,6 @@ import {
} from '../../store/selectors';
import {
multiSelect,
insertDefaultBlock,
selectBlock,
} from '../../store/actions';

Expand All @@ -41,10 +39,6 @@ import {
*/
const { UP, DOWN, LEFT, RIGHT } = keycodes;

function isElementNonEmpty( el ) {
return !! el.innerText.trim();
}

class WritingFlow extends Component {
constructor() {
super( ...arguments );
Expand Down Expand Up @@ -109,37 +103,6 @@ class WritingFlow extends Component {
} );
}

isInLastNonEmptyBlock( target ) {
const tabbables = this.getVisibleTabbables();

// Find last tabbable, compare with target
const lastTabbable = last( tabbables );
if ( ! lastTabbable || ! lastTabbable.contains( target ) ) {
return false;
}

// Find block-level ancestor of said last tabbable
const blockEl = lastTabbable.closest( '.' + BlockListBlock.className );
const blockIndex = tabbables.indexOf( blockEl );

// Unexpected, so we'll leave quietly.
if ( blockIndex === -1 ) {
return false;
}

// Maybe there are no descendants, and the target is the block itself?
if ( lastTabbable === blockEl ) {
return isElementNonEmpty( blockEl );
}

// Otherwise, find the descendants of the ancestor, i.e. the target and
// its siblings, and check them instead.
return tabbables
.slice( blockIndex + 1 )
.some( ( el ) =>
blockEl.contains( el ) && isElementNonEmpty( el ) );
}

expandSelection( currentStartUid, isReverse ) {
const { previousBlockUid, nextBlockUid } = this.props;

Expand Down Expand Up @@ -229,13 +192,6 @@ class WritingFlow extends Component {
this.selectParentBlock( closestTabbable );
event.preventDefault();
}

if ( isDown && ! isShift && ! hasMultiSelection &&
this.isInLastNonEmptyBlock( target ) &&
isVerticalEdge( target, false, false )
) {
this.props.onBottomReached();
}
}

render() {
Expand Down Expand Up @@ -267,7 +223,6 @@ export default connect(
} ),
{
onMultiSelect: multiSelect,
onBottomReached: insertDefaultBlock,
onSelectBlock: selectBlock,
}
)( WritingFlow );