From cd048c01547c19b90ff98afc174f618e1e1ebc44 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Tue, 19 Aug 2014 03:26:14 +0000 Subject: [PATCH] TinyMCE wpView: ignore more keys when the caret is around a view. Part props avryl, fixes #29115. git-svn-id: https://develop.svn.wordpress.org/trunk@29535 602fd350-edb4-49c9-b593-d223f7449a82 --- .../js/tinymce/plugins/wpview/plugin.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/js/tinymce/plugins/wpview/plugin.js b/src/wp-includes/js/tinymce/plugins/wpview/plugin.js index da12d957d3..e0dbafacca 100644 --- a/src/wp-includes/js/tinymce/plugins/wpview/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wpview/plugin.js @@ -353,6 +353,14 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { } }); + // Excludes arrow keys, delete, backspace, enter, space bar. + function isSpecialKey( key ) { + return ( ( key <= 47 && key !== VK.SPACEBAR && key !== VK.ENTER && key !== VK.DELETE && key !== VK.BACKSPACE && ( key < 37 || key > 40 ) ) || + key === 144 || key === 145 || // Num Lock, Scroll Lock + ( key >= 91 && key <= 93 ) || // Windows keys + ( key >= 112 && key <= 123 ) ); // F keys + } + // (De)select views when arrow keys are used to navigate the content of the editor. editor.on( 'keydown', function( event ) { var key = event.keyCode, @@ -410,9 +418,10 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { } else { setViewCursor( false, view ); } + event.preventDefault(); // Ignore keys that don't insert anything. - } else if ( ( key > 47 || VK.SPACEBAR || key === VK.ENTER || key === VK.DELETE || key === VK.BACKSPACE ) && key !== 144 && key !== 145 ) { + } else if ( ! isSpecialKey( key ) ) { removeView( selected ); if ( key === VK.ENTER || key === VK.DELETE || key === VK.BACKSPACE ) { @@ -472,6 +481,11 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { return; } + if ( isSpecialKey( key ) ) { + // ignore + return; + } + if ( ( cursorAfter && key === VK.UP ) || ( cursorBefore && key === VK.BACKSPACE ) ) { if ( view.previousSibling ) { if ( getView( view.previousSibling ) ) {