diff --git a/src/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js b/src/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js index d68904afb1..5f3ff1a827 100644 --- a/src/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js @@ -62,15 +62,14 @@ if ( event.keyCode === VK.ENTER && ! VK.modifierPressed( event ) ) { enter(); } - }, true ); - editor.on( 'keyup', function( event ) { + // Wait for the browser to insert the character. if ( event.keyCode === VK.SPACEBAR && ! event.ctrlKey && ! event.metaKey && ! event.altKey ) { - space(); + setTimeout( space ); } else if ( event.keyCode > 47 && ! ( event.keyCode >= 91 && event.keyCode <= 93 ) ) { - inline(); + setTimeout( inline ); } - } ); + }, true ); function inline() { var rng = editor.selection.getRng(); diff --git a/tests/qunit/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js b/tests/qunit/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js index edcb629876..73ba48b00d 100644 --- a/tests/qunit/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js +++ b/tests/qunit/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js @@ -6,7 +6,7 @@ return; } - function mceType(chr) { + function mceType( chr, noKeyUp ) { var editor = tinymce.activeEditor, keyCode, charCode, evt, startElm, rng, startContainer, startOffset, textNode; function charCodeToKeyCode(charCode) { @@ -109,12 +109,17 @@ } } - fakeEvent(startElm, 'keyup', evt); + if ( ! noKeyUp ) { + fakeEvent(startElm, 'keyup', evt); + } } function type() { var args = arguments; + // Wait once for conversions to be triggered, + // and once for the `canUndo` flag to be set. + setTimeout( function() { setTimeout( function() { if ( typeof args[0] === 'string' ) { args[0] = args[0].split( '' ); @@ -134,6 +139,7 @@ type.apply( null, args ); } } ); + } ); } QUnit.module( 'tinymce.plugins.wptextpattern', { @@ -177,6 +183,14 @@ }, assert.async() ); } ); + QUnit.test( 'Unordered list. (fast)', function( assert ) { + type( '*', function() { + mceType( ' ', true ); + }, 'a', function() { + assert.equal( editor.getContent(), '' ); + }, assert.async() ); + } ); + QUnit.test( 'Ordered list.', function( assert ) { type( '1. a', function() { assert.equal( editor.getContent(), '
    \n
  1. a
  2. \n
' );