From fbeb0e35b8c2f48ab8d1c193a9b5df9282e0d7a0 Mon Sep 17 00:00:00 2001 From: iseulde Date: Wed, 31 Oct 2018 18:20:34 +0100 Subject: [PATCH] Format boundaries WIP --- .../editor/src/components/rich-text/index.js | 4 +++- .../editor/src/components/rich-text/tinymce.js | 2 +- packages/rich-text/src/to-tree.js | 18 +++++++++++++++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/packages/editor/src/components/rich-text/index.js b/packages/editor/src/components/rich-text/index.js index 45158696b7a3d2..34e6d812b98c84 100644 --- a/packages/editor/src/components/rich-text/index.js +++ b/packages/editor/src/components/rich-text/index.js @@ -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; @@ -441,6 +442,7 @@ export class RichText extends Component { } this.setState( { start, end } ); + this.applyRecord( value ); } } diff --git a/packages/editor/src/components/rich-text/tinymce.js b/packages/editor/src/components/rich-text/tinymce.js index 9efd051c669082..733193d3e8f973 100644 --- a/packages/editor/src/components/rich-text/tinymce.js +++ b/packages/editor/src/components/rich-text/tinymce.js @@ -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: [], } ); diff --git a/packages/rich-text/src/to-tree.js b/packages/rich-text/src/to-tree.js index be23219851a96b..a44cafe1e64bc6 100644 --- a/packages/rich-text/src/to-tree.js +++ b/packages/rich-text/src/to-tree.js @@ -3,6 +3,7 @@ */ import { getFormatType } from './get-format-type'; +import { getActiveFormat } from './get-active-format'; import { LINE_SEPARATOR, OBJECT_REPLACEMENT_CHARACTER, @@ -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 ]; @@ -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, '' ); } ); }