From c676d0d62c127294c451501d52c884505eca248b Mon Sep 17 00:00:00 2001 From: "Lukhnos D. Liu" Date: Sat, 7 Apr 2012 01:14:55 -0700 Subject: [PATCH] Handle the case where text client fails to handle char attr request. --- Source/InputMethodController.mm | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Source/InputMethodController.mm b/Source/InputMethodController.mm index cffdc7d8..03403fb3 100644 --- a/Source/InputMethodController.mm +++ b/Source/InputMethodController.mm @@ -1034,14 +1034,20 @@ public: [self updateClientComposingBuffer:client]; _currentCandidateClient = client; - NSRect lineHeightRect; + NSRect lineHeightRect = NSMakeRect(0.0, 0.0, 16.0, 16.0); NSInteger cursor = _latestReadingCursor; if (cursor == [_composingBuffer length] && cursor != 0) { cursor--; } - [client attributesForCharacterIndex:cursor lineHeightRectangle:&lineHeightRect]; + // some apps (e.g. Twitter for Mac's search bar) handle this call incorrectly, hence the try-catch + @try { + [client attributesForCharacterIndex:cursor lineHeightRectangle:&lineHeightRect]; + } + @catch (NSException *exception) { + NSLog(@"%@", exception); + } [LTCurrentCandidateController setWindowTopLeftPoint:NSMakePoint(lineHeightRect.origin.x, lineHeightRect.origin.y - 4.0) bottomOutOfScreenAdjustmentHeight:lineHeightRect.size.height + 4.0]; LTCurrentCandidateController.visible = YES;