Skip to content

Commit

Permalink
Do not mutate attirbutes object
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Feb 4, 2019
1 parent 1a88924 commit 421876c
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions packages/rich-text/src/to-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,24 @@ import {
ZERO_WIDTH_NO_BREAK_SPACE,
} from './special-characters';

function fromFormat( { type, attributes, unregisteredAttributes, object } ) {
function fromFormat( { type, attributes, unregisteredAttributes, object, boundaryClass } ) {
const formatType = getFormatType( type );

let elementAttributes = {};

if ( boundaryClass ) {
elementAttributes[ 'data-rich-text-format-boundary' ] = 'true';
}

if ( ! formatType ) {
return { type, attributes, object };
if ( attributes ) {
elementAttributes = { ...attributes, ...elementAttributes };
}

return { type, attributes: elementAttributes, object };
}

const elementAttributes = { ...unregisteredAttributes };
elementAttributes = { ...unregisteredAttributes, ...elementAttributes };

for ( const name in attributes ) {
const key = formatType.attributes ? formatType.attributes[ name ] : false;
Expand Down Expand Up @@ -195,23 +205,22 @@ export function toTree( {
return;
}

const { type, attributes = {}, unregisteredAttributes, object } = format;
const { type, attributes, unregisteredAttributes, object } = format;

if (
const boundaryClass = (
isEditableTree &&
! object &&
character !== LINE_SEPARATOR &&
format === deepestActiveFormat
) {
attributes[ 'data-rich-text-format-boundary' ] = 'true';
}
);

const parent = getParent( pointer );
const newNode = append( parent, fromFormat( {
type,
attributes,
unregisteredAttributes,
object,
boundaryClass,
} ) );

if ( isText( pointer ) && getText( pointer ).length === 0 ) {
Expand Down

0 comments on commit 421876c

Please sign in to comment.