From 43b2de66c6a959d3bf3860fd188183e500948843 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Sun, 11 Jan 2015 20:41:36 +0000 Subject: [PATCH] TinyMCE wpView: when clicking in the editor optimize the caret placement before or after a view. Props avryl, fixes #30938. git-svn-id: https://develop.svn.wordpress.org/trunk@31143 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/tinymce/plugins/wpview/plugin.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/js/tinymce/plugins/wpview/plugin.js b/src/wp-includes/js/tinymce/plugins/wpview/plugin.js index 36a76675e2..2a9d496df0 100644 --- a/src/wp-includes/js/tinymce/plugins/wpview/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wpview/plugin.js @@ -162,7 +162,7 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { toolbar = editor.$( viewNode ).find( '.toolbar' ), editorToolbar = tinymce.$( editor.editorContainer ).find( '.mce-toolbar-grp' )[0], editorToolbarBottom = ( editorToolbar && editorToolbar.getBoundingClientRect().bottom ) || 0; - + if ( toolbar.length && editor.iframeElement ) { // 48 = 43 for the toolbar + 5 buffer delta = viewNode.getBoundingClientRect().top + editor.iframeElement.getBoundingClientRect().top - editorToolbarBottom - 48; @@ -264,10 +264,14 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { } else if ( y > lastRect.bottom && ( view = getView( last ) ) ) { setViewCursor( false, view ); event.preventDefault(); - } else { + } else if ( x < bodyRect.left || x > bodyRect.right ) { tinymce.each( editor.dom.select( '.wpview-wrap' ), function( view ) { var rect = view.getBoundingClientRect(); + if ( y < rect.top ) { + return false; + } + if ( y >= rect.top && y <= rect.bottom ) { if ( x < bodyRect.left ) { setViewCursor( true, view ); @@ -276,7 +280,8 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { setViewCursor( false, view ); event.preventDefault(); } - return; + + return false; } }); }