Skip to content

Commit

Permalink
Add initialised class for e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Oct 30, 2018
1 parent bb9bed0 commit b5a36c9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
34 changes: 22 additions & 12 deletions packages/editor/src/components/rich-text/tinymce.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ export default class TinyMCE extends Component {
browser_spellcheck: true,
entity_encoding: 'raw',
convert_urls: false,
// Disables TinyMCE's parsing to verify HTML. It makes
// initialisation a bit faster. Since we're setting raw HTML
// 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',
plugins: [],
Expand All @@ -171,28 +175,33 @@ export default class TinyMCE extends Component {
this.editor = editor;
this.props.onSetup( editor );

editor.on( 'init', () => {
// See https://github.com/tinymce/tinymce/blob/master/src/core/main/ts/keyboard/FormatShortcuts.ts
[ 'b', 'i', 'u' ].forEach( ( character ) => {
editor.shortcuts.remove( `meta+${ character }` );
} );
[ 1, 2, 3, 4, 5, 6, 7, 8, 9 ].forEach( ( number ) => {
editor.shortcuts.remove( `access+${ number }` );
} );
} );

// TinyMCE resets the element content on initialization, even
// when it's already identical to what exists currently. This
// behavior clobbers a selection which exists at the time of
// initialization, thus breaking writing flow navigation. The
// hack here neutralizes setHTML during initialization.
let setHTML;
editor.on( 'PreInit', () => {

editor.on( 'preinit', () => {
setHTML = editor.dom.setHTML;
editor.dom.setHTML = () => {};
} );
editor.on( 'Init', () => {

editor.on( 'init', () => {
// See https://github.com/tinymce/tinymce/blob/master/src/core/main/ts/keyboard/FormatShortcuts.ts
[ 'b', 'i', 'u' ].forEach( ( character ) => {
editor.shortcuts.remove( `meta+${ character }` );
} );
[ 1, 2, 3, 4, 5, 6, 7, 8, 9 ].forEach( ( number ) => {
editor.shortcuts.remove( `access+${ number }` );
} );

editor.dom.setHTML = setHTML;
tinymce.DOM.addClass( editor.getBody(), 'mce-initialised' );
} );

editor.on( 'remove', () => {
tinymce.DOM.removeClass( editor.getBody(), 'mce-initialised' );
} );
},
} );
Expand Down Expand Up @@ -264,6 +273,7 @@ export default class TinyMCE extends Component {
}

if ( initialHTML === '' ) {
// Ensure the field is ready to receive focus by TinyMCE.
initialHTML = '<br data-mce-bogus="1">';
}

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/support/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ async function waitForRichTextInitialization() {
}

return page.waitForFunction( () => {
return !! document.activeElement.closest( '.mce-content-body' );
return !! document.activeElement.closest( '.mce-initialised' );
} );
}

Expand Down

0 comments on commit b5a36c9

Please sign in to comment.