TinyMCE: wptextpattern: fix for fast typing

Props jnylen0, iseulde.

Fixes #36585.



git-svn-id: https://develop.svn.wordpress.org/trunk@37668 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ella Iseulde Van Dorpe 2016-06-09 19:06:25 +00:00
parent 363533d9b3
commit 644795a9dc
2 changed files with 20 additions and 7 deletions

View File

@ -62,15 +62,14 @@
if ( event.keyCode === VK.ENTER && ! VK.modifierPressed( event ) ) { if ( event.keyCode === VK.ENTER && ! VK.modifierPressed( event ) ) {
enter(); 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 ) { 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 ) ) { } else if ( event.keyCode > 47 && ! ( event.keyCode >= 91 && event.keyCode <= 93 ) ) {
inline(); setTimeout( inline );
} }
} ); }, true );
function inline() { function inline() {
var rng = editor.selection.getRng(); var rng = editor.selection.getRng();

View File

@ -6,7 +6,7 @@
return; return;
} }
function mceType(chr) { function mceType( chr, noKeyUp ) {
var editor = tinymce.activeEditor, keyCode, charCode, evt, startElm, rng, startContainer, startOffset, textNode; var editor = tinymce.activeEditor, keyCode, charCode, evt, startElm, rng, startContainer, startOffset, textNode;
function charCodeToKeyCode(charCode) { function charCodeToKeyCode(charCode) {
@ -109,12 +109,17 @@
} }
} }
if ( ! noKeyUp ) {
fakeEvent(startElm, 'keyup', evt); fakeEvent(startElm, 'keyup', evt);
} }
}
function type() { function type() {
var args = arguments; var args = arguments;
// Wait once for conversions to be triggered,
// and once for the `canUndo` flag to be set.
setTimeout( function() {
setTimeout( function() { setTimeout( function() {
if ( typeof args[0] === 'string' ) { if ( typeof args[0] === 'string' ) {
args[0] = args[0].split( '' ); args[0] = args[0].split( '' );
@ -134,6 +139,7 @@
type.apply( null, args ); type.apply( null, args );
} }
} ); } );
} );
} }
QUnit.module( 'tinymce.plugins.wptextpattern', { QUnit.module( 'tinymce.plugins.wptextpattern', {
@ -177,6 +183,14 @@
}, assert.async() ); }, assert.async() );
} ); } );
QUnit.test( 'Unordered list. (fast)', function( assert ) {
type( '*', function() {
mceType( ' ', true );
}, 'a', function() {
assert.equal( editor.getContent(), '<ul>\n<li>a</li>\n</ul>' );
}, assert.async() );
} );
QUnit.test( 'Ordered list.', function( assert ) { QUnit.test( 'Ordered list.', function( assert ) {
type( '1. a', function() { type( '1. a', function() {
assert.equal( editor.getContent(), '<ol>\n<li>a</li>\n</ol>' ); assert.equal( editor.getContent(), '<ol>\n<li>a</li>\n</ol>' );