Skip to content

Commit

Permalink
Try fixing the tab navigation issue (#12390)
Browse files Browse the repository at this point in the history
* Try fixing the tab navigation issue

* Fix block selection reducer
  • Loading branch information
youknowriad authored Nov 28, 2018
1 parent e4fd51c commit b5d4e15
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
12 changes: 0 additions & 12 deletions packages/editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,18 +682,6 @@ export class RichText extends Component {
this.savedContent = value;
}

// If blocks are merged, but the content remains the same, e.g. merging
// an empty paragraph into another, then also set the selection to the
// end.
if ( isSelected && ! prevProps.isSelected && ! this.isActive() ) {
const record = this.formatToValue( value );
const prevRecord = this.formatToValue( prevProps.value );
const length = getTextContent( prevRecord ).length;
record.start = length;
record.end = length;
this.applyRecord( record );
}

// If any format props update, reapply value.
const shouldReapply = Object.keys( this.props ).some( ( name ) => {
if ( name.indexOf( 'format_' ) !== 0 ) {
Expand Down
3 changes: 3 additions & 0 deletions packages/editor/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,9 @@ export function blockSelection( state = {
// If there is replacement block(s), assign first's client ID as
// the next selected block. If empty replacement, reset to null.
const nextSelectedBlockClientId = get( action.blocks, [ 0, 'clientId' ], null );
if ( nextSelectedBlockClientId === state.start && nextSelectedBlockClientId === state.end ) {
return state;
}

return {
...state,
Expand Down
19 changes: 19 additions & 0 deletions packages/editor/src/store/test/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1761,6 +1761,25 @@ describe( 'state', () => {
} );
} );

it( 'should not replace the selected block if we keep it when replacing blocks', () => {
const original = deepFreeze( { start: 'chicken', end: 'chicken' } );
const state = blockSelection( original, {
type: 'REPLACE_BLOCKS',
clientIds: [ 'chicken' ],
blocks: [
{
clientId: 'chicken',
name: 'core/freeform',
},
{
clientId: 'wings',
name: 'core/freeform',
} ],
} );

expect( state ).toBe( original );
} );

it( 'should reset if replacing with empty set', () => {
const original = deepFreeze( { start: 'chicken', end: 'chicken' } );
const state = blockSelection( original, {
Expand Down

0 comments on commit b5d4e15

Please sign in to comment.