Editor focus: Don't trigger when typing while the mouse is outside the editor.

props avryl.
fixes #20668.


git-svn-id: https://develop.svn.wordpress.org/trunk@30817 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin 2014-12-11 09:33:46 +00:00
parent 9bda766f54
commit 560b6f7978

View File

@ -803,6 +803,12 @@
mouseY = event.pageY; mouseY = event.pageY;
} ); } );
function recalcEditorRect() {
editorRect = $editor.offset();
editorRect.right = editorRect.left + $editor.outerWidth();
editorRect.bottom = editorRect.top + $editor.outerHeight();
}
function activate() { function activate() {
if ( ! _isActive ) { if ( ! _isActive ) {
_isActive = true; _isActive = true;
@ -909,9 +915,7 @@
$overlay $overlay
// Always recalculate the editor area entering the overlay with the mouse. // Always recalculate the editor area entering the overlay with the mouse.
.on( 'mouseenter.focus', function() { .on( 'mouseenter.focus', function() {
editorRect = $editor.offset(); recalcEditorRect();
editorRect.right = editorRect.left + $editor.outerWidth();
editorRect.bottom = editorRect.top + $editor.outerHeight();
$window.on( 'scroll.focus', function() { $window.on( 'scroll.focus', function() {
var nScrollY = window.pageYOffset; var nScrollY = window.pageYOffset;
@ -937,24 +941,26 @@
} ) } )
// Fade in when the mouse moves away form the editor area. // Fade in when the mouse moves away form the editor area.
.on( 'mousemove.focus', function( event ) { .on( 'mousemove.focus', function( event ) {
var nx = event.pageX, var nx = event.clientX,
ny = event.pageY; ny = event.clientY,
pageYOffset = window.pageYOffset,
pageXOffset = window.pageXOffset;
if ( x && y && ( nx !== x || ny !== y ) ) { if ( x && y && ( nx !== x || ny !== y ) ) {
if ( if (
( ny <= y && ny < editorRect.top ) || ( ny <= y && ny < editorRect.top - pageYOffset ) ||
( ny >= y && ny > editorRect.bottom ) || ( ny >= y && ny > editorRect.bottom - pageYOffset ) ||
( nx <= x && nx < editorRect.left ) || ( nx <= x && nx < editorRect.left - pageXOffset ) ||
( nx >= x && nx > editorRect.right ) ( nx >= x && nx > editorRect.right - pageXOffset )
) { ) {
traveledX += Math.abs( x - nx ); traveledX += Math.abs( x - nx );
traveledY += Math.abs( y - ny ); traveledY += Math.abs( y - ny );
if ( ( if ( (
ny <= editorRect.top - buffer || ny <= editorRect.top - buffer - pageYOffset ||
ny >= editorRect.bottom + buffer || ny >= editorRect.bottom + buffer - pageYOffset ||
nx <= editorRect.left - buffer || nx <= editorRect.left - buffer - pageXOffset ||
nx >= editorRect.right + buffer nx >= editorRect.right + buffer - pageXOffset
) && ( ) && (
traveledX > 10 || traveledX > 10 ||
traveledY > 10 traveledY > 10
@ -1151,6 +1157,7 @@
editor.on( 'blur', maybeFadeIn ); editor.on( 'blur', maybeFadeIn );
editor.on( 'focus', focus ); editor.on( 'focus', focus );
editor.on( 'blur', blur ); editor.on( 'blur', blur );
editor.on( 'wp-autoresize', recalcEditorRect );
}; };
mceUnbind = function() { mceUnbind = function() {
@ -1158,6 +1165,7 @@
editor.off( 'blur', maybeFadeIn ); editor.off( 'blur', maybeFadeIn );
editor.off( 'focus', focus ); editor.off( 'focus', focus );
editor.off( 'blur', blur ); editor.off( 'blur', blur );
editor.off( 'wp-autoresize', recalcEditorRect );
}; };
if ( _isOn ) { if ( _isOn ) {