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
This commit is contained in:
parent
d66ac05792
commit
29093fe8dc
|
@ -30,19 +30,31 @@
|
||||||
tinymce.each( editor.dom.$( 'img._inserted-emoji', node ), setImgAttr );
|
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 ) {
|
if ( isWin8 ) {
|
||||||
// Windows 8+ emoji can be "typed" with the onscreen keyboard.
|
// Windows 8+ emoji can be "typed" with the onscreen keyboard.
|
||||||
// That triggers the normal keyboard events, but not the 'input' event.
|
// That triggers the normal keyboard events, but not the 'input' event.
|
||||||
// Thankfully it sets keyCode 231 when the onscreen keyboard inserts any emoji.
|
// Thankfully it sets keyCode 231 when the onscreen keyboard inserts any emoji.
|
||||||
editor.on( 'keyup', function( event ) {
|
editor.on( 'keyup', function( event ) {
|
||||||
var node;
|
|
||||||
|
|
||||||
if ( event.keyCode === 231 ) {
|
if ( event.keyCode === 231 ) {
|
||||||
node = editor.selection.getNode();
|
parseNode( editor.selection.getNode() );
|
||||||
|
|
||||||
if ( twemoji.test( node.textContent || node.innerText ) ) {
|
|
||||||
replaceEmoji( node );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
} else if ( ! isWin ) {
|
} else if ( ! isWin ) {
|
||||||
|
@ -58,21 +70,7 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var bookmark,
|
parseNode( editor.selection.getNode() );
|
||||||
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 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue