Fix Plain Bopomofo regression (#71)
This is caused by a missing method. Our implementation for -[NSObject(IMKServerInput) inputText🔑modifiers:client:] was changed to handleEvent: in 0.9.5. Interestingly, calling -inputText🔑modifiers:client: somehow worked when we linked against OS X 10.7 SDK (that was the SDK the 0.9.5 distribution used). This is no longer true with OS X 10.8 SDK.
This commit is contained in:
parent
fe182ba26b
commit
9448c1af48
|
@ -129,6 +129,7 @@ FastLM gLanguageModelPlainBopomofo;
|
||||||
- (void)_showCandidateWindowUsingVerticalMode:(BOOL)useVerticalMode client:(id)client;
|
- (void)_showCandidateWindowUsingVerticalMode:(BOOL)useVerticalMode client:(id)client;
|
||||||
|
|
||||||
- (void)beep;
|
- (void)beep;
|
||||||
|
- (BOOL)handleInputText:(NSString*)inputText key:(NSInteger)keyCode modifiers:(NSUInteger)flags client:(id)client;
|
||||||
- (BOOL)handleCandidateEventWithInputText:(NSString *)inputText charCode:(UniChar)charCode keyCode:(NSUInteger)keyCode;
|
- (BOOL)handleCandidateEventWithInputText:(NSString *)inputText charCode:(UniChar)charCode keyCode:(NSUInteger)keyCode;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -506,193 +507,8 @@ public:
|
||||||
NSBeep();
|
NSBeep();
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)handleCandidateEventWithInputText:(NSString *)inputText charCode:(UniChar)charCode keyCode:(NSUInteger)keyCode
|
- (BOOL)handleInputText:(NSString*)inputText key:(NSInteger)keyCode modifiers:(NSUInteger)flags client:(id)client
|
||||||
{
|
{
|
||||||
if (_inputMode == kPlainBopomofoModeIdentifier) {
|
|
||||||
if (charCode == '<') {
|
|
||||||
keyCode = kPageUpKeyCode;
|
|
||||||
}
|
|
||||||
else if (charCode == '>') {
|
|
||||||
keyCode = kPageDownKeyCode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (charCode == 27) {
|
|
||||||
gCurrentCandidateController.visible = NO;
|
|
||||||
[_candidates removeAllObjects];
|
|
||||||
|
|
||||||
if (_inputMode == kPlainBopomofoModeIdentifier) {
|
|
||||||
_builder->clear();
|
|
||||||
_walkedNodes.clear();
|
|
||||||
[_composingBuffer setString:@""];
|
|
||||||
}
|
|
||||||
[self updateClientComposingBuffer:_currentCandidateClient];
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
else if (charCode == 13 || keyCode == kEnterKeyCode) {
|
|
||||||
[self candidateController:gCurrentCandidateController didSelectCandidateAtIndex:gCurrentCandidateController.selectedCandidateIndex];
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
else if (charCode == 32 || keyCode == kPageDownKeyCode) {
|
|
||||||
BOOL updated = [gCurrentCandidateController showNextPage];
|
|
||||||
if (!updated) {
|
|
||||||
[self beep];
|
|
||||||
}
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
else if (keyCode == kPageUpKeyCode) {
|
|
||||||
BOOL updated = [gCurrentCandidateController showPreviousPage];
|
|
||||||
if (!updated) {
|
|
||||||
[self beep];
|
|
||||||
}
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
else if (keyCode == kLeftKeyCode) {
|
|
||||||
if ([gCurrentCandidateController isKindOfClass:[VTHorizontalCandidateController class]]) {
|
|
||||||
BOOL updated = [gCurrentCandidateController highlightPreviousCandidate];
|
|
||||||
if (!updated) {
|
|
||||||
[self beep];
|
|
||||||
}
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
[self beep];
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (keyCode == kRightKeyCode) {
|
|
||||||
if ([gCurrentCandidateController isKindOfClass:[VTHorizontalCandidateController class]]) {
|
|
||||||
BOOL updated = [gCurrentCandidateController highlightNextCandidate];
|
|
||||||
if (!updated) {
|
|
||||||
[self beep];
|
|
||||||
}
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
[self beep];
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (keyCode == kUpKeyCode) {
|
|
||||||
if ([gCurrentCandidateController isKindOfClass:[VTHorizontalCandidateController class]]) {
|
|
||||||
BOOL updated = [gCurrentCandidateController showPreviousPage];
|
|
||||||
if (!updated) {
|
|
||||||
[self beep];
|
|
||||||
}
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
BOOL updated = [gCurrentCandidateController highlightPreviousCandidate];
|
|
||||||
if (!updated) {
|
|
||||||
[self beep];
|
|
||||||
}
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (keyCode == kDownKeyCode) {
|
|
||||||
if ([gCurrentCandidateController isKindOfClass:[VTHorizontalCandidateController class]]) {
|
|
||||||
BOOL updated = [gCurrentCandidateController showNextPage];
|
|
||||||
if (!updated) {
|
|
||||||
[self beep];
|
|
||||||
}
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
BOOL updated = [gCurrentCandidateController highlightNextCandidate];
|
|
||||||
if (!updated) {
|
|
||||||
[self beep];
|
|
||||||
}
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (keyCode == kHomeKeyCode) {
|
|
||||||
if (gCurrentCandidateController.selectedCandidateIndex == 0) {
|
|
||||||
[self beep];
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
gCurrentCandidateController.selectedCandidateIndex = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
else if (keyCode == kEndKeyCode && [_candidates count] > 0) {
|
|
||||||
if (gCurrentCandidateController.selectedCandidateIndex == [_candidates count] - 1) {
|
|
||||||
[self beep];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
gCurrentCandidateController.selectedCandidateIndex = [_candidates count] - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
NSInteger index = NSNotFound;
|
|
||||||
for (NSUInteger j = 0, c = [gCurrentCandidateController.keyLabels count]; j < c; j++) {
|
|
||||||
if ([inputText compare:[gCurrentCandidateController.keyLabels objectAtIndex:j] options:NSCaseInsensitiveSearch] == NSOrderedSame) {
|
|
||||||
index = j;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[gCurrentCandidateController.keyLabels indexOfObject:inputText];
|
|
||||||
if (index != NSNotFound) {
|
|
||||||
NSUInteger candidateIndex = [gCurrentCandidateController candidateIndexAtKeyLabelIndex:index];
|
|
||||||
if (candidateIndex != NSUIntegerMax) {
|
|
||||||
[self candidateController:gCurrentCandidateController didSelectCandidateAtIndex:candidateIndex];
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_inputMode == kPlainBopomofoModeIdentifier) {
|
|
||||||
if (_bpmfReadingBuffer->isValidKey((char)charCode)) {
|
|
||||||
NSUInteger candidateIndex = [gCurrentCandidateController candidateIndexAtKeyLabelIndex:0];
|
|
||||||
if (candidateIndex != NSUIntegerMax) {
|
|
||||||
[self candidateController:gCurrentCandidateController didSelectCandidateAtIndex:candidateIndex];
|
|
||||||
return [self inputText:inputText key:keyCode modifiers:0 client:_currentCandidateClient];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[self beep];
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSUInteger)recognizedEvents:(id)sender
|
|
||||||
{
|
|
||||||
return NSKeyDownMask | NSFlagsChangedMask;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (BOOL)handleEvent:(NSEvent *)event client:(id)client
|
|
||||||
{
|
|
||||||
if ([event type] == NSFlagsChanged) {
|
|
||||||
// function key pressed
|
|
||||||
BOOL includeShift = [[NSUserDefaults standardUserDefaults] boolForKey:kFunctionKeyKeyboardLayoutOverrideIncludeShiftKey];
|
|
||||||
if (([event modifierFlags] & ~NSShiftKeyMask) || (([event modifierFlags] & NSShiftKeyMask) && includeShift)) {
|
|
||||||
NSString *functionKeyKeyboardLayoutID = [[NSUserDefaults standardUserDefaults] stringForKey:kFunctionKeyKeyboardLayoutPreferenceKey];
|
|
||||||
if (!functionKeyKeyboardLayoutID) {
|
|
||||||
functionKeyKeyboardLayoutID = @"com.apple.keylayout.US";
|
|
||||||
}
|
|
||||||
|
|
||||||
[client overrideKeyboardWithKeyboardNamed:functionKeyKeyboardLayoutID];
|
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
// reset when function key is released
|
|
||||||
NSString *basisKeyboardLayoutID = [[NSUserDefaults standardUserDefaults] stringForKey:kBasisKeyboardLayoutPreferenceKey];
|
|
||||||
if (!basisKeyboardLayoutID) {
|
|
||||||
basisKeyboardLayoutID = @"com.apple.keylayout.US";
|
|
||||||
}
|
|
||||||
|
|
||||||
[client overrideKeyboardWithKeyboardNamed:basisKeyboardLayoutID];
|
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
NSString *inputText = [event characters];
|
|
||||||
NSInteger keyCode = [event keyCode];
|
|
||||||
NSUInteger flags = [event modifierFlags];
|
|
||||||
|
|
||||||
NSRect textFrame = NSZeroRect;
|
NSRect textFrame = NSZeroRect;
|
||||||
NSDictionary *attributes = nil;
|
NSDictionary *attributes = nil;
|
||||||
|
|
||||||
|
@ -1121,6 +937,195 @@ public:
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)handleCandidateEventWithInputText:(NSString *)inputText charCode:(UniChar)charCode keyCode:(NSUInteger)keyCode
|
||||||
|
{
|
||||||
|
if (_inputMode == kPlainBopomofoModeIdentifier) {
|
||||||
|
if (charCode == '<') {
|
||||||
|
keyCode = kPageUpKeyCode;
|
||||||
|
}
|
||||||
|
else if (charCode == '>') {
|
||||||
|
keyCode = kPageDownKeyCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (charCode == 27) {
|
||||||
|
gCurrentCandidateController.visible = NO;
|
||||||
|
[_candidates removeAllObjects];
|
||||||
|
|
||||||
|
if (_inputMode == kPlainBopomofoModeIdentifier) {
|
||||||
|
_builder->clear();
|
||||||
|
_walkedNodes.clear();
|
||||||
|
[_composingBuffer setString:@""];
|
||||||
|
}
|
||||||
|
[self updateClientComposingBuffer:_currentCandidateClient];
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
else if (charCode == 13 || keyCode == kEnterKeyCode) {
|
||||||
|
[self candidateController:gCurrentCandidateController didSelectCandidateAtIndex:gCurrentCandidateController.selectedCandidateIndex];
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
else if (charCode == 32 || keyCode == kPageDownKeyCode) {
|
||||||
|
BOOL updated = [gCurrentCandidateController showNextPage];
|
||||||
|
if (!updated) {
|
||||||
|
[self beep];
|
||||||
|
}
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
else if (keyCode == kPageUpKeyCode) {
|
||||||
|
BOOL updated = [gCurrentCandidateController showPreviousPage];
|
||||||
|
if (!updated) {
|
||||||
|
[self beep];
|
||||||
|
}
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
else if (keyCode == kLeftKeyCode) {
|
||||||
|
if ([gCurrentCandidateController isKindOfClass:[VTHorizontalCandidateController class]]) {
|
||||||
|
BOOL updated = [gCurrentCandidateController highlightPreviousCandidate];
|
||||||
|
if (!updated) {
|
||||||
|
[self beep];
|
||||||
|
}
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
[self beep];
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (keyCode == kRightKeyCode) {
|
||||||
|
if ([gCurrentCandidateController isKindOfClass:[VTHorizontalCandidateController class]]) {
|
||||||
|
BOOL updated = [gCurrentCandidateController highlightNextCandidate];
|
||||||
|
if (!updated) {
|
||||||
|
[self beep];
|
||||||
|
}
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
[self beep];
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (keyCode == kUpKeyCode) {
|
||||||
|
if ([gCurrentCandidateController isKindOfClass:[VTHorizontalCandidateController class]]) {
|
||||||
|
BOOL updated = [gCurrentCandidateController showPreviousPage];
|
||||||
|
if (!updated) {
|
||||||
|
[self beep];
|
||||||
|
}
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
BOOL updated = [gCurrentCandidateController highlightPreviousCandidate];
|
||||||
|
if (!updated) {
|
||||||
|
[self beep];
|
||||||
|
}
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (keyCode == kDownKeyCode) {
|
||||||
|
if ([gCurrentCandidateController isKindOfClass:[VTHorizontalCandidateController class]]) {
|
||||||
|
BOOL updated = [gCurrentCandidateController showNextPage];
|
||||||
|
if (!updated) {
|
||||||
|
[self beep];
|
||||||
|
}
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
BOOL updated = [gCurrentCandidateController highlightNextCandidate];
|
||||||
|
if (!updated) {
|
||||||
|
[self beep];
|
||||||
|
}
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (keyCode == kHomeKeyCode) {
|
||||||
|
if (gCurrentCandidateController.selectedCandidateIndex == 0) {
|
||||||
|
[self beep];
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
gCurrentCandidateController.selectedCandidateIndex = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
else if (keyCode == kEndKeyCode && [_candidates count] > 0) {
|
||||||
|
if (gCurrentCandidateController.selectedCandidateIndex == [_candidates count] - 1) {
|
||||||
|
[self beep];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
gCurrentCandidateController.selectedCandidateIndex = [_candidates count] - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
NSInteger index = NSNotFound;
|
||||||
|
for (NSUInteger j = 0, c = [gCurrentCandidateController.keyLabels count]; j < c; j++) {
|
||||||
|
if ([inputText compare:[gCurrentCandidateController.keyLabels objectAtIndex:j] options:NSCaseInsensitiveSearch] == NSOrderedSame) {
|
||||||
|
index = j;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[gCurrentCandidateController.keyLabels indexOfObject:inputText];
|
||||||
|
if (index != NSNotFound) {
|
||||||
|
NSUInteger candidateIndex = [gCurrentCandidateController candidateIndexAtKeyLabelIndex:index];
|
||||||
|
if (candidateIndex != NSUIntegerMax) {
|
||||||
|
[self candidateController:gCurrentCandidateController didSelectCandidateAtIndex:candidateIndex];
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_inputMode == kPlainBopomofoModeIdentifier) {
|
||||||
|
if (_bpmfReadingBuffer->isValidKey((char)charCode)) {
|
||||||
|
NSUInteger candidateIndex = [gCurrentCandidateController candidateIndexAtKeyLabelIndex:0];
|
||||||
|
if (candidateIndex != NSUIntegerMax) {
|
||||||
|
[self candidateController:gCurrentCandidateController didSelectCandidateAtIndex:candidateIndex];
|
||||||
|
return [self handleInputText:inputText key:keyCode modifiers:0 client:_currentCandidateClient];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[self beep];
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSUInteger)recognizedEvents:(id)sender
|
||||||
|
{
|
||||||
|
return NSKeyDownMask | NSFlagsChangedMask;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)handleEvent:(NSEvent *)event client:(id)client
|
||||||
|
{
|
||||||
|
if ([event type] == NSFlagsChanged) {
|
||||||
|
// function key pressed
|
||||||
|
BOOL includeShift = [[NSUserDefaults standardUserDefaults] boolForKey:kFunctionKeyKeyboardLayoutOverrideIncludeShiftKey];
|
||||||
|
if (([event modifierFlags] & ~NSShiftKeyMask) || (([event modifierFlags] & NSShiftKeyMask) && includeShift)) {
|
||||||
|
NSString *functionKeyKeyboardLayoutID = [[NSUserDefaults standardUserDefaults] stringForKey:kFunctionKeyKeyboardLayoutPreferenceKey];
|
||||||
|
if (!functionKeyKeyboardLayoutID) {
|
||||||
|
functionKeyKeyboardLayoutID = @"com.apple.keylayout.US";
|
||||||
|
}
|
||||||
|
|
||||||
|
[client overrideKeyboardWithKeyboardNamed:functionKeyKeyboardLayoutID];
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
// reset when function key is released
|
||||||
|
NSString *basisKeyboardLayoutID = [[NSUserDefaults standardUserDefaults] stringForKey:kBasisKeyboardLayoutPreferenceKey];
|
||||||
|
if (!basisKeyboardLayoutID) {
|
||||||
|
basisKeyboardLayoutID = @"com.apple.keylayout.US";
|
||||||
|
}
|
||||||
|
|
||||||
|
[client overrideKeyboardWithKeyboardNamed:basisKeyboardLayoutID];
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSString *inputText = [event characters];
|
||||||
|
NSInteger keyCode = [event keyCode];
|
||||||
|
NSUInteger flags = [event modifierFlags];
|
||||||
|
return [self handleInputText:inputText key:keyCode modifiers:flags client:client];
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - Private methods
|
#pragma mark - Private methods
|
||||||
|
|
||||||
+ (VTHorizontalCandidateController *)horizontalCandidateController
|
+ (VTHorizontalCandidateController *)horizontalCandidateController
|
||||||
|
|
Loading…
Reference in New Issue