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 );