From 42ac48d52a48530e22838173ecf50341c8fc703d Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Sat, 26 Jul 2014 00:07:55 +0000 Subject: [PATCH] TinyMCE: - Fix complex character input in Japanese, Chinese, etc. Was broken in getCursorOffset() in editor-expand.js. - Disable auto-scrolling in some edge cases when editor expanding is enabled. See #28328. git-svn-id: https://develop.svn.wordpress.org/trunk@29302 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/js/editor-expand.js | 71 +++++++------------ .../js/tinymce/plugins/wpview/plugin.js | 3 +- 2 files changed, 26 insertions(+), 48 deletions(-) diff --git a/src/wp-admin/js/editor-expand.js b/src/wp-admin/js/editor-expand.js index bc255553c8..8cc3f80ff1 100644 --- a/src/wp-admin/js/editor-expand.js +++ b/src/wp-admin/js/editor-expand.js @@ -124,13 +124,18 @@ jQuery( document ).ready( function($) { $visualEditor = $contentWrap.find( '.mce-edit-area' ); $statusBar = $contentWrap.find( '.mce-statusbar' ).filter( ':visible' ); - // Adjust when switching editor modes. - editor.on( 'show', function() { - setTimeout( function() { - editor.execCommand( 'wpAutoResize' ); - adjust(); - }, 300 ); - } ); + function getCursorOffset() { + var node = editor.selection.getNode(), + view, offset; + + if ( editor.plugins.wpview && ( view = editor.plugins.wpview.getView( node ) ) ) { + offset = view.getBoundingClientRect(); + } else { + offset = node.getBoundingClientRect(); + } + + return offset.height ? offset : false; + } // Make sure the cursor is always visible. // This is not only necessary to keep the cursor between the toolbars, @@ -150,13 +155,18 @@ jQuery( document ).ready( function($) { return; } - cursorTop = offset.top + editor.getContentAreaContainer().getElementsByTagName( 'iframe' )[0].getBoundingClientRect().top; + cursorTop = offset.top + editor.getContentAreaContainer().firstChild.getBoundingClientRect().top; cursorBottom = cursorTop + offset.height; cursorTop = cursorTop - buffer; cursorBottom = cursorBottom + buffer; editorTop = $adminBar.outerHeight() + $tools.outerHeight() + $visualTop.outerHeight(); editorBottom = windowHeight - $bottom.outerHeight(); + // Don't scroll if the node is taller than the visible part of the editor + if ( editorBottom - editorTop < offset.height ) { + return; + } + if ( cursorTop < editorTop && ( key === VK.UP || key === VK.LEFT || key === VK.BACKSPACE ) ) { window.scrollTo( window.pageXOffset, cursorTop + window.pageYOffset - editorTop ); } else if ( cursorBottom > editorBottom ) { @@ -164,44 +174,13 @@ jQuery( document ).ready( function($) { } } ); - function getCursorOffset() { - var selection = editor.selection, - node = selection.getNode(), - range = selection.getRng(), - view, clone, offset; - - if ( tinymce.Env.ie && tinymce.Env.ie < 9 ) { - return; - } - - if ( editor.plugins.wpview && ( view = editor.plugins.wpview.getView( node ) ) ) { - offset = view.getBoundingClientRect(); - } else if ( selection.isCollapsed() ) { - clone = range.cloneRange(); - - if ( clone.startContainer.length > 1 ) { - if ( clone.startContainer.length > clone.endOffset ) { - clone.setEnd( clone.startContainer, clone.endOffset + 1 ); - } else { - clone.setStart( clone.startContainer, clone.endOffset - 1 ); - } - - selection.setRng( clone ); - offset = selection.getRng().getBoundingClientRect(); - selection.setRng( range ); - } else { - offset = node.getBoundingClientRect(); - } - } else { - offset = range.getBoundingClientRect(); - } - - if ( ! offset.height ) { - return; - } - - return offset; - } + // Adjust when switching editor modes. + editor.on( 'show', function() { + setTimeout( function() { + editor.execCommand( 'wpAutoResize' ); + adjust(); + }, 300 ); + } ); editor.on( 'hide', function() { textEditorResize(); diff --git a/src/wp-includes/js/tinymce/plugins/wpview/plugin.js b/src/wp-includes/js/tinymce/plugins/wpview/plugin.js index f770ada825..bb4f22972a 100644 --- a/src/wp-includes/js/tinymce/plugins/wpview/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wpview/plugin.js @@ -286,8 +286,7 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { }); editor.dom.bind( editor.getBody().parentNode, 'mousedown mouseup click', function( event ) { - var view = getView( event.target ), - deselectEventType; + var view = getView( event.target ); firstFocus = false;