Skip to content

Commit

Permalink
Format boundaries WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Nov 14, 2018
1 parent 721dbab commit fbeb0e3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
4 changes: 3 additions & 1 deletion packages/editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,8 @@ export class RichText extends Component {
return;
}

const { start, end, formats } = this.createRecord();
const value = this.createRecord();
const { start, end, formats } = value;

if ( start !== this.state.start || end !== this.state.end ) {
const isCaretWithinFormattedText = this.props.isCaretWithinFormattedText;
Expand All @@ -441,6 +442,7 @@ export class RichText extends Component {
}

this.setState( { start, end } );
this.applyRecord( value );
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/editor/src/components/rich-text/tinymce.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export default class TinyMCE extends Component {
// already with dangerouslySetInnerHTML, we don't need this to be
// verified.
verify_html: false,
inline_boundaries_selector: 'a[href],code,b,i,strong,em,del,ins,sup,sub',
// inline_boundaries_selector: 'a[href],code,b,i,strong,em,del,ins,sup,sub',
plugins: [],
} );

Expand Down
18 changes: 15 additions & 3 deletions packages/rich-text/src/to-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

import { getFormatType } from './get-format-type';
import { getActiveFormat } from './get-active-format';
import {
LINE_SEPARATOR,
OBJECT_REPLACEMENT_CHARACTER,
Expand All @@ -19,7 +20,7 @@ function fromFormat( { type, attributes, unregisteredAttributes, object } ) {
const elementAttributes = { ...unregisteredAttributes };

for ( const name in attributes ) {
const key = formatType.attributes[ name ];
const key = formatType.attributes ? formatType.attributes[ name ] : false;

if ( key ) {
elementAttributes[ key ] = attributes[ name ];
Expand Down Expand Up @@ -146,14 +147,25 @@ export function toTree( {
return;
}

const { type, attributes = {}, object } = format;
const activeFormat = getActiveFormat( value, type );

if ( format === activeFormat ) {
attributes[ 'data-mce-selected' ] = 'inline-boundary';
}

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

if ( isText( pointer ) && getText( pointer ).length === 0 ) {
remove( pointer );
}

pointer = append( format.object ? parent : newNode, '' );
pointer = append( object ? parent : newNode, '' );
} );
}

Expand Down

0 comments on commit fbeb0e3

Please sign in to comment.