From 06c90fd4f2937b316275bed70e6303eabc949bff Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Sun, 13 Feb 2022 23:15:14 +0800 Subject: [PATCH] Zonble: KeyHandler // Allow BPMF output via Ctrl+Enter. --- .../Modules/ControllerModules/KeyHandler.mm | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Source/Modules/ControllerModules/KeyHandler.mm b/Source/Modules/ControllerModules/KeyHandler.mm index c4c77b14..9f57243c 100644 --- a/Source/Modules/ControllerModules/KeyHandler.mm +++ b/Source/Modules/ControllerModules/KeyHandler.mm @@ -490,6 +490,9 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; // MARK: Enter if (charCode == 13) { + if ([input isControlHold]) { + return [self _handleCtrlEnterWithState:state stateCallback:stateCallback errorCallback:errorCallback]; + } return [self _handleEnterWithState:state stateCallback:stateCallback errorCallback:errorCallback]; } @@ -791,6 +794,24 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; return YES; } +- (BOOL)_handleCtrlEnterWithState:(InputState *)state stateCallback:(void (^)(InputState *))stateCallback errorCallback:(void (^)(void))errorCallback +{ + if (![state isKindOfClass:[InputStateInputting class]]) { + return NO; + } + + NSArray *readings = [self _currentReadings]; + NSString *composingBuffer = [readings componentsJoinedByString:@"-"]; + + [self clear]; + + InputStateCommitting *committing = [[InputStateCommitting alloc] initWithPoppedText:composingBuffer]; + stateCallback(committing); + InputStateEmpty *empty = [[InputStateEmpty alloc] init]; + stateCallback(empty); + return YES; +} + - (BOOL)_handleEnterWithState:(InputState *)state stateCallback:(void (^)(InputState *))stateCallback errorCallback:(void (^)(void))errorCallback { if (![state isKindOfClass:[InputStateInputting class]]) {