From 29093fe8dcbc42426a6c9365cbb495259f4cf796 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Tue, 31 Mar 2015 23:34:23 +0000 Subject: [PATCH] TinyMCE emoji: fix caret position after replacing emoji in Chrome on Windows 8. See #31627. git-svn-id: https://develop.svn.wordpress.org/trunk@31946 602fd350-edb4-49c9-b593-d223f7449a82 --- .../js/tinymce/plugins/wpemoji/plugin.js | 42 +++++++++---------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/src/wp-includes/js/tinymce/plugins/wpemoji/plugin.js b/src/wp-includes/js/tinymce/plugins/wpemoji/plugin.js index d4ae77b007..a2fbb094db 100644 --- a/src/wp-includes/js/tinymce/plugins/wpemoji/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wpemoji/plugin.js @@ -30,19 +30,31 @@ tinymce.each( editor.dom.$( 'img._inserted-emoji', node ), setImgAttr ); } + // Test if the node text contains emoji char(s) and replace. + function parseNode( node ) { + var selection, bookmark; + + if ( node && twemoji.test( node.textContent || node.innerText ) ) { + if ( env.webkit ) { + selection = editor.selection; + bookmark = selection.getBookmark(); + } + + replaceEmoji( node ); + + if ( env.webkit ) { + selection.moveToBookmark( bookmark ); + } + } + } + if ( isWin8 ) { // Windows 8+ emoji can be "typed" with the onscreen keyboard. // That triggers the normal keyboard events, but not the 'input' event. // Thankfully it sets keyCode 231 when the onscreen keyboard inserts any emoji. editor.on( 'keyup', function( event ) { - var node; - if ( event.keyCode === 231 ) { - node = editor.selection.getNode(); - - if ( twemoji.test( node.textContent || node.innerText ) ) { - replaceEmoji( node ); - } + parseNode( editor.selection.getNode() ); } } ); } else if ( ! isWin ) { @@ -58,21 +70,7 @@ return; } - var bookmark, - selection = editor.selection, - node = selection.getNode(); - - if ( twemoji.test( node.textContent || node.innerText ) ) { - if ( env.webkit ) { - bookmark = selection.getBookmark(); - } - - replaceEmoji( node ); - - if ( env.webkit ) { - selection.moveToBookmark( bookmark ); - } - } + parseNode( editor.selection.getNode() ); }); }