From 7d0d1056c08f66f20b598161d13fa5b4d4ca2748 Mon Sep 17 00:00:00 2001 From: Blair Duncan Date: Thu, 4 Apr 2013 12:44:15 -0400 Subject: [PATCH] =?UTF-8?q?Fixed=20=E2=80=93=20Menus=20no=20longer=20respo?= =?UTF-8?q?nd=20to=20keyboard=20navigation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a menu is active, menu selection should change as characters are typed. This can be seen in the manual CPMenuTest. It used to work in the past but with all of the changes in the last few months to the compiler I was not able to track down the exact commit that broke it. The code responsible for clearing the _keybuffer after a brief delay in typing, was not being called, resulting in a build up of characters. This commit moves the check for delay to the interpretKeyEvent and takes care of clearing the _keybuffer itself and removes that responsibility from the selection method. --- AppKit/CPMenu/_CPMenuManager.j | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/AppKit/CPMenu/_CPMenuManager.j b/AppKit/CPMenu/_CPMenuManager.j index 83a8377e0..dd5b7abaf 100644 --- a/AppKit/CPMenu/_CPMenuManager.j +++ b/AppKit/CPMenu/_CPMenuManager.j @@ -214,15 +214,6 @@ var STICKY_TIME_INTERVAL = 0.4, [self _trackAgain]; - if (_keyBuffer) - { - if (([anEvent timestamp] - _startTime) > (STICKY_TIME_INTERVAL + [activeMenu numberOfItems] / 2)) - [self selectNextItemBeginningWith:_keyBuffer inMenu:menu clearBuffer:YES]; - - if (type === CPPeriodic) - return; - } - // unhighlight when mouse is moved off the menu if (_lastGlobalLocation && CGRectContainsPoint([activeMenuContainer globalFrame], _lastGlobalLocation) && !CGRectContainsPoint([activeMenuContainer globalFrame], globalLocation)) @@ -563,6 +554,9 @@ var STICKY_TIME_INTERVAL = 0.4, } else if (!(modifierFlags & (CPCommandKeyMask | CPControlKeyMask))) { + if (([anEvent timestamp] - _startTime) > STICKY_TIME_INTERVAL) + _keyBuffer = nil; + if (!_keyBuffer) { _startTime = [anEvent timestamp]; @@ -574,12 +568,12 @@ var STICKY_TIME_INTERVAL = 0.4, else _keyBuffer += character; - [self selectNextItemBeginningWith:_keyBuffer inMenu:menu clearBuffer:NO]; - _lastGlobalLocation = Nil; + [self selectNextItemBeginningWith:_keyBuffer inMenu:menu]; + _lastGlobalLocation = nil; } } -- (void)selectNextItemBeginningWith:(CPString)characters inMenu:(CPMenu)menu clearBuffer:(BOOL)shouldClear +- (void)selectNextItemBeginningWith:(CPString)characters inMenu:(CPMenu)menu { var iter = [[menu itemArray] objectEnumerator], obj; @@ -596,13 +590,7 @@ var STICKY_TIME_INTERVAL = 0.4, } } - if (shouldClear) - { - [CPEvent stopPeriodicEvents]; - _keyBuffer = Nil; - } - else - _startTime = [CPEvent currentTimestamp]; + _startTime = [CPEvent currentTimestamp]; } - (void)scrollToBeginningOfDocument:(CPMenu)menu