Skip to content

Commit

Permalink
Rich Text: Replace existing active format in applied
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed May 10, 2019
1 parent 32b4af8 commit c8c5ed4
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/rich-text/src/apply-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External dependencies
*/

import { find } from 'lodash';
import { find, reject } from 'lodash';

/**
* Internal dependencies
Expand Down Expand Up @@ -34,7 +34,7 @@ export function applyFormat(
startIndex = value.start,
endIndex = value.end
) {
const { formats, activeFormats = [] } = value;
const { formats, activeFormats } = value;
const newFormats = formats.slice();

// The selection is collapsed.
Expand Down Expand Up @@ -91,6 +91,9 @@ export function applyFormat(
// Always revise active formats. This serves as a placeholder for new
// inputs with the format so new input appears with the format applied,
// and ensures a format of the same type uses the latest values.
activeFormats: [ format, ...activeFormats ],
activeFormats: [
...reject( activeFormats, { type: format.type } ),
format,
],
} );
}

0 comments on commit c8c5ed4

Please sign in to comment.