TinyMCE wpView: better handling of the Enter key, props avryl, see #28595

Built from https://develop.svn.wordpress.org/trunk@29127


git-svn-id: http://core.svn.wordpress.org/trunk@28912 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2014-07-13 00:34:15 +00:00
parent 3282885519
commit fa53f86393
3 changed files with 18 additions and 21 deletions

View File

@ -74,31 +74,28 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
editor.nodeChanged(); editor.nodeChanged();
} }
function handleEnter( view, before ) { function handleEnter( view, before, keyCode ) {
var dom = editor.dom, 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' ); padNode = dom.create( 'p' );
if ( ! ( Env.ie && Env.ie < 11 ) ) { if ( ! ( Env.ie && Env.ie < 11 ) ) {
padNode.innerHTML = '<br data-mce-bogus="1">'; padNode.innerHTML = '<br data-mce-bogus="1">';
} }
if ( before ) { if ( before ) {
view.parentNode.insertBefore( padNode, view ); view.parentNode.insertBefore( padNode, view );
} else { } else {
dom.insertAfter( padNode, view ); dom.insertAfter( padNode, view );
}
} }
deselect(); 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(); editor.nodeChanged();
} }
@ -456,7 +453,7 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
} else if ( cursorAfter ) { } else if ( cursorAfter ) {
handleEnter( view ); handleEnter( view );
} else if ( cursorBefore ) { } else if ( cursorBefore ) {
handleEnter( view , true); handleEnter( view , true, keyCode );
} }
if ( keyCode === VK.ENTER ) { if ( keyCode === VK.ENTER ) {
@ -630,7 +627,7 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
}, 500 ); }, 500 );
// If the cursor lands anywhere else in the view, set the cursor before it. // 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.) // 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(); deselect();
setViewCursorTries++; setViewCursorTries++;
setViewCursor( true, view ); setViewCursor( true, view );

File diff suppressed because one or more lines are too long