Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/WordPress/gutenberg into …
Browse files Browse the repository at this point in the history
…rnmobile/887-History-stack-is-not-empty-on-a-fresh-start-of-the-editor

* 'master' of https://github.com/WordPress/gutenberg:
  'string' misspelled as 'srting' (#15118)
  [Mobile] Improving accessibility on Post title (#15106)
  Fix 13776: Format is already registered to handle class name (#15072)
  Add wpDataSelect WordPress end 2 end test util (#15052)
  Block Editor: move selection state from RichText to the store (#14640)
  chore: Fix: Lint error that makes unit tests (and CI tests) fail. (#15073)
  Set ownProps.onFocus when context.onFocus is undefined. (#15069)
  • Loading branch information
daniloercoli committed Apr 23, 2019
2 parents 6d648c8 + 2cfd306 commit 61d1323
Show file tree
Hide file tree
Showing 25 changed files with 615 additions and 370 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,32 @@ Returns the number of blocks currently present in the post.

Number of blocks in the post.

### getSelectionStart

Returns the current selection start block client ID, attribute key and text
offset.

*Parameters*

* state: Block editor state.

*Returns*

Selection start information.

### getSelectionEnd

Returns the current selection end block client ID, attribute key and text
offset.

*Parameters*

* state: Block editor state.

*Returns*

Selection end information.

### getBlockSelectionStart

Returns the current block selection start. This value may be null, and it
Expand Down Expand Up @@ -1042,6 +1068,18 @@ Returns an action object used in signalling that the caret has entered formatted

Returns an action object used in signalling that the user caret has exited formatted text.

### selectionChange

Returns an action object used in signalling that the user caret has changed
position.

*Parameters*

* clientId: The selected block client ID.
* attributeKey: The selected block attribute key.
* startOffset: The start offset.
* endOffset: The end offset.

### insertDefaultBlock

Returns an action object used in signalling that a new block of the default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ exports[`BlockControls should render a dynamic toolbar of controls 1`] = `
value={
Object {
"clientId": undefined,
"focusedElement": null,
"isSelected": true,
"name": undefined,
"onFocus": undefined,
"setFocusedElement": [Function],
}
}
>
Expand Down
49 changes: 21 additions & 28 deletions packages/block-editor/src/components/block-edit/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import memize from 'memize';

/**
* WordPress dependencies
*/
Expand All @@ -10,40 +15,28 @@ import Edit from './edit';
import { BlockEditContextProvider } from './context';

class BlockEdit extends Component {
constructor( props ) {
super( props );

this.setFocusedElement = this.setFocusedElement.bind( this );

this.state = {
focusedElement: null,
setFocusedElement: this.setFocusedElement,
};
constructor() {
super( ...arguments );

// It is important to return the same object if props haven't changed
// to avoid unnecessary rerenders.
// See https://reactjs.org/docs/context.html#caveats.
this.propsToContext = memize(
this.propsToContext.bind( this ),
{ maxSize: 1 }
);
}

setFocusedElement( focusedElement ) {
this.setState( ( prevState ) => {
if ( prevState.focusedElement === focusedElement ) {
return null;
}
return { focusedElement };
} );
}

static getDerivedStateFromProps( props ) {
const { clientId, name, isSelected, onFocus } = props;

return {
name,
isSelected,
clientId,
onFocus,
};
propsToContext( name, isSelected, clientId, onFocus ) {
return { name, isSelected, clientId, onFocus };
}

render() {
const { name, isSelected, clientId, onFocus } = this.props;
const value = this.propsToContext( name, isSelected, clientId, onFocus );

return (
<BlockEditContextProvider value={ this.state }>
<BlockEditContextProvider value={ value }>
<Edit { ...this.props } />
</BlockEditContextProvider>
);
Expand Down
9 changes: 1 addition & 8 deletions packages/block-editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
focus,
isTextField,
placeCaretAtHorizontalEdge,
placeCaretAtVerticalEdge,
} from '@wordpress/dom';
import { BACKSPACE, DELETE, ENTER } from '@wordpress/keycodes';
import {
Expand Down Expand Up @@ -154,13 +153,7 @@ export class BlockListBlock extends Component {
return;
}

target.focus();

// In reverse case, need to explicitly place caret position.
if ( isReverse ) {
placeCaretAtHorizontalEdge( target, true );
placeCaretAtVerticalEdge( target, true );
}
placeCaretAtHorizontalEdge( target, isReverse );
}

setAttributes( attributes ) {
Expand Down
Loading

0 comments on commit 61d1323

Please sign in to comment.