From 9cc9f95cd2f1075a02cf1c0bebc78300afc3c84d Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Sun, 13 Jul 2014 00:33:58 +0000 Subject: [PATCH] TinyMCE wpView: better handling of the Enter key, props avryl, see #28595 git-svn-id: https://develop.svn.wordpress.org/trunk@29127 602fd350-edb4-49c9-b593-d223f7449a82 --- .../js/tinymce/plugins/wpview/plugin.js | 37 +++++++++---------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/src/wp-includes/js/tinymce/plugins/wpview/plugin.js b/src/wp-includes/js/tinymce/plugins/wpview/plugin.js index 0f21cfea81..1c6b57e3f1 100644 --- a/src/wp-includes/js/tinymce/plugins/wpview/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wpview/plugin.js @@ -74,31 +74,28 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { editor.nodeChanged(); } - function handleEnter( view, before ) { + function handleEnter( view, before, keyCode ) { var dom = editor.dom, - padNode; - - if ( ! before && view.nextSibling && dom.isEmpty( view.nextSibling ) && view.nextSibling.nodeName === 'P' ) { - padNode = view.nextSibling; - } else if ( before && view.previousSibling && dom.isEmpty( view.previousSibling ) && view.previousSibling.nodeName === 'P' ) { - padNode = view.previousSibling; - } else { padNode = dom.create( 'p' ); - if ( ! ( Env.ie && Env.ie < 11 ) ) { - padNode.innerHTML = '
'; - } + if ( ! ( Env.ie && Env.ie < 11 ) ) { + padNode.innerHTML = '
'; + } - if ( before ) { - view.parentNode.insertBefore( padNode, view ); - } else { - dom.insertAfter( padNode, view ); - } + if ( before ) { + view.parentNode.insertBefore( padNode, view ); + } else { + dom.insertAfter( padNode, view ); } deselect(); - editor.getBody().focus(); - editor.selection.setCursorLocation( padNode, 0 ); + + if ( before && keyCode === VK.ENTER ) { + setViewCursor( before, view ); + } else { + editor.selection.setCursorLocation( padNode, 0 ); + } + editor.nodeChanged(); } @@ -456,7 +453,7 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { } else if ( cursorAfter ) { handleEnter( view ); } else if ( cursorBefore ) { - handleEnter( view , true); + handleEnter( view , true, keyCode ); } if ( keyCode === VK.ENTER ) { @@ -630,7 +627,7 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { }, 500 ); // If the cursor lands anywhere else in the view, set the cursor before it. // Only try this once to prevent a loop. (You never know.) - } else if ( ! getParent( event.element, 'wpview-body' ) && ! setViewCursorTries ) { + } else if ( ! getParent( event.element, 'wpview-clipboard' ) && ! setViewCursorTries ) { deselect(); setViewCursorTries++; setViewCursor( true, view );