From cb0d7a82f51c5ed20ed1398f920b2503db722259 Mon Sep 17 00:00:00 2001 From: zonble Date: Sun, 2 Oct 2011 14:20:35 +0800 Subject: [PATCH] Fixes an exception. --- Source/InputMethodController.mm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Source/InputMethodController.mm b/Source/InputMethodController.mm index 6210dd1d..d836deea 100644 --- a/Source/InputMethodController.mm +++ b/Source/InputMethodController.mm @@ -422,8 +422,16 @@ public: - (BOOL)inputText:(NSString*)inputText key:(NSInteger)keyCode modifiers:(NSUInteger)flags client:(id)client { NSRect textFrame = NSZeroRect; - NSDictionary *attributes = [client attributesForCharacterIndex:0 lineHeightRectangle:&textFrame]; - BOOL userVerticalMode = [attributes objectForKey:@"IMKTextOrientation"] && [[attributes objectForKey:@"IMKTextOrientation"] integerValue] == 0; + NSDictionary *attributes = nil; + BOOL userVerticalMode = NO; + @try { + attributes = [client attributesForCharacterIndex:0 lineHeightRectangle:&textFrame]; + userVerticalMode = [attributes objectForKey:@"IMKTextOrientation"] && [[attributes objectForKey:@"IMKTextOrientation"] integerValue] == 0; + } + @catch (NSException *e) { + // An exception may raise while using Twitter.app's search filed. + } + NSInteger leftKey = userVerticalMode ? 125 : 124; NSInteger rightKey = userVerticalMode ? 126 : 123; NSInteger downKey = userVerticalMode ? 123 : 125;