Skip to content

Commit

Permalink
Improve the heuristics to account for a block + paragraph.
Browse files Browse the repository at this point in the history
  • Loading branch information
mtias committed Oct 31, 2017
1 parent 6e6ebb3 commit 3f75acf
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion editor/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -951,12 +951,20 @@ export function getSuggestedPostFormat( state ) {
const blocks = state.editor.blockOrder;

let name;
// If there is only one block in the content of the post grab its name so
// If there is only one block in the content of the post grab its name
// so we can derive a suitable post format from it.
if ( blocks.length === 1 ) {
name = state.editor.blocksByUid[ blocks[ 0 ] ].name;
}

// If there are two blocks in the content and the last one is a text blocks
// grab the name of the first one to also suggest a post format from it.
if ( blocks.length === 2 ) {
if ( state.editor.blocksByUid[ blocks[ 1 ] ].name === 'core/paragraph' ) {
name = state.editor.blocksByUid[ blocks[ 0 ] ].name;
}
}

// We only convert to default post formats in core.
switch ( name ) {
case 'core/image':
Expand Down

0 comments on commit 3f75acf

Please sign in to comment.