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();
}
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 = '<br data-mce-bogus="1">';
}
if ( ! ( Env.ie && Env.ie < 11 ) ) {
padNode.innerHTML = '<br data-mce-bogus="1">';
}
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 );

File diff suppressed because one or more lines are too long