- 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
This commit is contained in:
Andrew Ozz 2014-07-26 00:07:55 +00:00
parent 357d96c367
commit 42ac48d52a
2 changed files with 26 additions and 48 deletions

View File

@ -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();

View File

@ -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;