Skip to content

Commit

Permalink
Writing Flow: Move on KeyUp instead
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Aug 29, 2017
1 parent 69f244b commit 961c92c
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion editor/writing-flow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ class WritingFlow extends Component {
super( ...arguments );
this.zones = [];
this.onKeyDown = this.onKeyDown.bind( this );
this.onKeyUp = this.onKeyUp.bind( this );
this.bindContainer = this.bindContainer.bind( this );
this.state = {
shouldMove: false,
};
}

bindContainer( ref ) {
Expand Down Expand Up @@ -60,8 +64,18 @@ class WritingFlow extends Component {
const moveDown = ( keyCode === DOWN || keyCode === RIGHT );

if ( ( moveUp || moveDown ) && isEdge( target, moveUp ) ) {
this.moveFocusInContainer( target, moveUp ? 'UP' : 'DOWN' );
event.preventDefault();
this.setState( { shouldMove: true } );
}
}

onKeyUp( event ) {
const { keyCode, target } = event;
const moveUp = ( keyCode === UP || keyCode === LEFT );
if ( this.state.shouldMove ) {
event.preventDefault();
this.moveFocusInContainer( target, moveUp ? 'UP' : 'DOWN' );
this.setState( { shouldMove: false } );
}
}

Expand All @@ -72,6 +86,7 @@ class WritingFlow extends Component {
<div
ref={ this.bindContainer }
onKeyDown={ this.onKeyDown }
onKeyUp={ this.onKeyUp }
>
{ children }
</div>
Expand Down

0 comments on commit 961c92c

Please sign in to comment.