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
This commit is contained in:
parent
c46233940f
commit
9cc9f95cd2
|
@ -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 );
|
||||
|
|
Loading…
Reference in New Issue