From eeceaa0c9b5a475b4a2cc1d6eed6637c6f6158d3 Mon Sep 17 00:00:00 2001 From: Blair Duncan Date: Fri, 1 Jun 2012 20:17:09 -0400 Subject: [PATCH] unlite if mouse is moved off and cursor up hilites last item if none --- AppKit/CPMenu/_CPMenuManager.j | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/AppKit/CPMenu/_CPMenuManager.j b/AppKit/CPMenu/_CPMenuManager.j index e78b08475..d8a92c39c 100644 --- a/AppKit/CPMenu/_CPMenuManager.j +++ b/AppKit/CPMenu/_CPMenuManager.j @@ -137,10 +137,7 @@ var STICKY_TIME_INTERVAL = 0.5, // Periodic events don't have a valid location. var globalLocation = type === CPPeriodic ? _lastGlobalLocation : [anEvent globalLocation]; - // Remember this for the next periodic event. - _lastGlobalLocation = globalLocation; - - if (!_lastGlobalLocation) + if (!globalLocation) return; // Find which menu window the mouse is currently on top of @@ -152,6 +149,14 @@ var STICKY_TIME_INTERVAL = 0.5, activeItemIndex = activeMenuContainer ? [activeMenuContainer itemIndexAtPoint:menuLocation] : CPNotFound, activeItem = activeItemIndex !== CPNotFound ? [activeMenu itemAtIndex:activeItemIndex] : nil; + // unhighlight when mouse is moved off the menu + if (_lastGlobalLocation && CGRectContainsPoint([activeMenuContainer globalFrame], _lastGlobalLocation) + && !CGRectContainsPoint([activeMenuContainer globalFrame], globalLocation)) + [activeMenu _highlightItemAtIndex:CPNotFound]; + + // Remember this for the next periodic event. + _lastGlobalLocation = globalLocation; + // If the item isn't enabled its as if we clicked on nothing. if (![activeItem isEnabled] || [activeItem _isMenuBarButton]) { @@ -667,8 +672,11 @@ var STICKY_TIME_INTERVAL = 0.5, var index = menu._highlightedIndex - 1; if (index < 0) + { + if (index != CPNotFound) + [menu _highlightItemAtIndex:[menu numberOfItems] - 1]; return; - + } [menu _highlightItemAtIndex:index]; var item = [menu highlightedItem];