Skip to content

Commit

Permalink
Merge pull request #10 from Automattic/fix/reselect
Browse files Browse the repository at this point in the history
Fix reselect after moving block
  • Loading branch information
mtias authored Feb 8, 2017
2 parents 001f8d1 + 1912e71 commit addfc61
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,23 @@ function attachControlActions() {
event.stopPropagation();
swapNodes( selectedBlock, getPreviousSibling( selectedBlock ) );
attachBlockHandlers();
reselect();
}, false );
} else if ( 'down' === classes ) {
node.addEventListener( 'click', function() {
event.stopPropagation();
swapNodes( selectedBlock, getNextSibling( selectedBlock ) );
attachBlockHandlers();
reselect();
}, false );
}
} );
}

function reselect() {
document.getElementsByClassName( 'is-selected' )[0].click();
}

function swapNodes( a, b ) {
if ( ! ( a && b ) ) {
return false;
Expand All @@ -130,9 +136,6 @@ function swapNodes( a, b ) {
return false;
}

// how do we handle controls?
showControls( b );

// insert node copies before removal
parent.replaceChild( b.cloneNode( true ), a );
parent.replaceChild( a.cloneNode( true ), b );
Expand Down

0 comments on commit addfc61

Please sign in to comment.