diff --git a/MMBackend.m b/MMBackend.m index 06ae1ebca8..8e342263cc 100644 --- a/MMBackend.m +++ b/MMBackend.m @@ -421,16 +421,8 @@ static int specialKeyToNSKey(int key); if (VIM_WARNING == type) style = NSWarningAlertStyle; else if (VIM_ERROR == type) style = NSCriticalAlertStyle; - NSString *hotkey = [NSString stringWithFormat:@"%c", DLG_HOTKEY_CHAR]; - NSMutableString *btnString = [NSMutableString stringWithUTF8String:btns]; - [btnString replaceOccurrencesOfString:hotkey - withString:@"" - options:0 - range:NSMakeRange(0, [btnString length])]; - - NSString *separator = [NSString stringWithFormat:@"%c", DLG_BUTTON_SEP]; - NSArray *buttons = [btnString componentsSeparatedByString:separator]; - + NSString *btnString = [NSString stringWithUTF8String:btns]; + NSArray *buttons = [btnString componentsSeparatedByString:@"\n"]; NSString *message = [NSString stringWithUTF8String:title]; NSString *text = [NSString stringWithUTF8String:msg]; diff --git a/MMVimController.m b/MMVimController.m index 559ce0e71b..d245887905 100644 --- a/MMVimController.m +++ b/MMVimController.m @@ -243,7 +243,33 @@ static NSMenuItem *findMenuItemWithTagInMenu(NSMenu *root, int tag) unsigned i, count = [buttons count]; for (i = 0; i < count; ++i) { NSString *title = [buttons objectAtIndex:i]; + // NOTE: The title of the button may contain the character '&' to + // indicate that the following letter should be the key equivalent + // associated with the button. Extract this letter and lowercase it. + NSString *keyEquivalent = nil; + NSRange hotkeyRange = [title rangeOfString:@"&"]; + if (NSNotFound != hotkeyRange.location) { + if ([title length] > NSMaxRange(hotkeyRange)) { + NSRange keyEquivRange = NSMakeRange(hotkeyRange.location+1, 1); + keyEquivalent = [[title substringWithRange:keyEquivRange] + lowercaseString]; + } + + NSMutableString *string = [NSMutableString stringWithString:title]; + [string deleteCharactersInRange:hotkeyRange]; + title = string; + } + [alert addButtonWithTitle:title]; + + // Set key equivalent for the button, but only if NSAlert hasn't + // already done so. (Check the documentation for + // - [NSAlert addButtonWithTitle:] to see what key equivalents are + // automatically assigned.) + NSButton *btn = [[alert buttons] lastObject]; + if ([[btn keyEquivalent] length] == 0 && keyEquivalent) { + [btn setKeyEquivalent:keyEquivalent]; + } } [alert beginSheetModalForWindow:[windowController window]