Skip to content

Commit

Permalink
RichText: Paste: merge active formats
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Apr 4, 2019
1 parent 5cf4e14 commit 886b180
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/block-editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,21 @@ export class RichText extends Component {
} );

if ( typeof content === 'string' ) {
const { activeFormats = [] } = this.state;
const recordToInsert = create( { html: content } );

// If there are active formats, merge them with the pasted formats.
if ( activeFormats.length ) {
let index = recordToInsert.formats.length;

while ( index-- ) {
recordToInsert.formats[ index ] = [
...activeFormats,
...( recordToInsert.formats[ index ] || [] ),
];
}
}

this.onChange( insert( record, recordToInsert ) );
} else if ( this.onSplit ) {
if ( ! content.length ) {
Expand Down

0 comments on commit 886b180

Please sign in to comment.