Skip to content

Commit 11243a9

Browse files
authored
Merge pull request #21822 from anntzer/nsd
Replace NSDictionary by switch-case.
2 parents 2e4189b + 8773ff4 commit 11243a9

File tree

1 file changed

+41
-43
lines changed

1 file changed

+41
-43
lines changed

src/_macosx.m

+41-43
Original file line numberDiff line numberDiff line change
@@ -1595,47 +1595,6 @@ - (void)removeRubberband
15951595

15961596
- (const char*)convertKeyEvent:(NSEvent*)event
15971597
{
1598-
NSDictionary* specialkeymappings = [NSDictionary dictionaryWithObjectsAndKeys:
1599-
@"left", [NSNumber numberWithUnsignedLong:NSLeftArrowFunctionKey],
1600-
@"right", [NSNumber numberWithUnsignedLong:NSRightArrowFunctionKey],
1601-
@"up", [NSNumber numberWithUnsignedLong:NSUpArrowFunctionKey],
1602-
@"down", [NSNumber numberWithUnsignedLong:NSDownArrowFunctionKey],
1603-
@"f1", [NSNumber numberWithUnsignedLong:NSF1FunctionKey],
1604-
@"f2", [NSNumber numberWithUnsignedLong:NSF2FunctionKey],
1605-
@"f3", [NSNumber numberWithUnsignedLong:NSF3FunctionKey],
1606-
@"f4", [NSNumber numberWithUnsignedLong:NSF4FunctionKey],
1607-
@"f5", [NSNumber numberWithUnsignedLong:NSF5FunctionKey],
1608-
@"f6", [NSNumber numberWithUnsignedLong:NSF6FunctionKey],
1609-
@"f7", [NSNumber numberWithUnsignedLong:NSF7FunctionKey],
1610-
@"f8", [NSNumber numberWithUnsignedLong:NSF8FunctionKey],
1611-
@"f9", [NSNumber numberWithUnsignedLong:NSF9FunctionKey],
1612-
@"f10", [NSNumber numberWithUnsignedLong:NSF10FunctionKey],
1613-
@"f11", [NSNumber numberWithUnsignedLong:NSF11FunctionKey],
1614-
@"f12", [NSNumber numberWithUnsignedLong:NSF12FunctionKey],
1615-
@"f13", [NSNumber numberWithUnsignedLong:NSF13FunctionKey],
1616-
@"f14", [NSNumber numberWithUnsignedLong:NSF14FunctionKey],
1617-
@"f15", [NSNumber numberWithUnsignedLong:NSF15FunctionKey],
1618-
@"f16", [NSNumber numberWithUnsignedLong:NSF16FunctionKey],
1619-
@"f17", [NSNumber numberWithUnsignedLong:NSF17FunctionKey],
1620-
@"f18", [NSNumber numberWithUnsignedLong:NSF18FunctionKey],
1621-
@"f19", [NSNumber numberWithUnsignedLong:NSF19FunctionKey],
1622-
@"scroll_lock", [NSNumber numberWithUnsignedLong:NSScrollLockFunctionKey],
1623-
@"break", [NSNumber numberWithUnsignedLong:NSBreakFunctionKey],
1624-
@"insert", [NSNumber numberWithUnsignedLong:NSInsertFunctionKey],
1625-
@"delete", [NSNumber numberWithUnsignedLong:NSDeleteFunctionKey],
1626-
@"home", [NSNumber numberWithUnsignedLong:NSHomeFunctionKey],
1627-
@"end", [NSNumber numberWithUnsignedLong:NSEndFunctionKey],
1628-
@"pagedown", [NSNumber numberWithUnsignedLong:NSPageDownFunctionKey],
1629-
@"pageup", [NSNumber numberWithUnsignedLong:NSPageUpFunctionKey],
1630-
@"backspace", [NSNumber numberWithUnsignedLong:NSDeleteCharacter],
1631-
@"enter", [NSNumber numberWithUnsignedLong:NSEnterCharacter],
1632-
@"tab", [NSNumber numberWithUnsignedLong:NSTabCharacter],
1633-
@"enter", [NSNumber numberWithUnsignedLong:NSCarriageReturnCharacter],
1634-
@"backtab", [NSNumber numberWithUnsignedLong:NSBackTabCharacter],
1635-
@"escape", [NSNumber numberWithUnsignedLong:27],
1636-
nil
1637-
];
1638-
16391598
NSMutableString* returnkey = [NSMutableString string];
16401599
if (keyChangeControl) {
16411600
// When control is the key that was pressed, return the full word
@@ -1658,8 +1617,47 @@ - (const char*)convertKeyEvent:(NSEvent*)event
16581617
// flagsChanged event can't handle charactersIgnoringModifiers
16591618
// because it was a modifier key that was pressed/released
16601619
if (event.type != NSEventTypeFlagsChanged) {
1661-
unichar uc = [[event charactersIgnoringModifiers] characterAtIndex:0];
1662-
NSString *specialchar = [specialkeymappings objectForKey:[NSNumber numberWithUnsignedLong:uc]];
1620+
NSString* specialchar;
1621+
switch ([[event charactersIgnoringModifiers] characterAtIndex:0]) {
1622+
case NSLeftArrowFunctionKey: specialchar = @"left"; break;
1623+
case NSRightArrowFunctionKey: specialchar = @"right"; break;
1624+
case NSUpArrowFunctionKey: specialchar = @"up"; break;
1625+
case NSDownArrowFunctionKey: specialchar = @"down"; break;
1626+
case NSF1FunctionKey: specialchar = @"f1"; break;
1627+
case NSF2FunctionKey: specialchar = @"f2"; break;
1628+
case NSF3FunctionKey: specialchar = @"f3"; break;
1629+
case NSF4FunctionKey: specialchar = @"f4"; break;
1630+
case NSF5FunctionKey: specialchar = @"f5"; break;
1631+
case NSF6FunctionKey: specialchar = @"f6"; break;
1632+
case NSF7FunctionKey: specialchar = @"f7"; break;
1633+
case NSF8FunctionKey: specialchar = @"f8"; break;
1634+
case NSF9FunctionKey: specialchar = @"f9"; break;
1635+
case NSF10FunctionKey: specialchar = @"f10"; break;
1636+
case NSF11FunctionKey: specialchar = @"f11"; break;
1637+
case NSF12FunctionKey: specialchar = @"f12"; break;
1638+
case NSF13FunctionKey: specialchar = @"f13"; break;
1639+
case NSF14FunctionKey: specialchar = @"f14"; break;
1640+
case NSF15FunctionKey: specialchar = @"f15"; break;
1641+
case NSF16FunctionKey: specialchar = @"f16"; break;
1642+
case NSF17FunctionKey: specialchar = @"f17"; break;
1643+
case NSF18FunctionKey: specialchar = @"f18"; break;
1644+
case NSF19FunctionKey: specialchar = @"f19"; break;
1645+
case NSScrollLockFunctionKey: specialchar = @"scroll_lock"; break;
1646+
case NSBreakFunctionKey: specialchar = @"break"; break;
1647+
case NSInsertFunctionKey: specialchar = @"insert"; break;
1648+
case NSDeleteFunctionKey: specialchar = @"delete"; break;
1649+
case NSHomeFunctionKey: specialchar = @"home"; break;
1650+
case NSEndFunctionKey: specialchar = @"end"; break;
1651+
case NSPageDownFunctionKey: specialchar = @"pagedown"; break;
1652+
case NSPageUpFunctionKey: specialchar = @"pageup"; break;
1653+
case NSDeleteCharacter: specialchar = @"backspace"; break;
1654+
case NSEnterCharacter: specialchar = @"enter"; break;
1655+
case NSTabCharacter: specialchar = @"tab"; break;
1656+
case NSCarriageReturnCharacter: specialchar = @"enter"; break;
1657+
case NSBackTabCharacter: specialchar = @"backtab"; break;
1658+
case 27: specialchar = @"escape"; break;
1659+
default: specialchar = nil;
1660+
}
16631661
if (specialchar) {
16641662
if (([event modifierFlags] & NSEventModifierFlagShift) || keyChangeShift) {
16651663
[returnkey appendString:@"shift+"];

0 commit comments

Comments
 (0)