From 0cdf0020c141824bac396f82b537d2c618673308 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Tue, 19 Apr 2022 13:46:03 +0800 Subject: [PATCH] KeyHandler // Refactoring "buildAssociatePhraseStateWithKey". --- Source/Modules/ControllerModules/KeyHandler.h | 1 + Source/Modules/ControllerModules/KeyHandler.mm | 18 ++++++++++++------ .../ControllerModules/KeyHandler_States.swift | 4 +++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Source/Modules/ControllerModules/KeyHandler.h b/Source/Modules/ControllerModules/KeyHandler.h index 787f8e86..231f653b 100644 --- a/Source/Modules/ControllerModules/KeyHandler.h +++ b/Source/Modules/ControllerModules/KeyHandler.h @@ -74,6 +74,7 @@ struct BufferStatePackage - (BOOL)ifLangModelHasUnigramsForKey:(NSString *)reading; - (BOOL)isPhoneticReadingBufferEmpty; - (BOOL)isPrintable:(UniChar)charCode; +- (NSArray *)buildAssociatePhraseArrayWithKey:(NSString *)key; - (NSArray *)getCandidatesArray; - (NSInteger)getBuilderCursorIndex; - (NSInteger)getBuilderLength; diff --git a/Source/Modules/ControllerModules/KeyHandler.mm b/Source/Modules/ControllerModules/KeyHandler.mm index 503f188e..3f8be28b 100644 --- a/Source/Modules/ControllerModules/KeyHandler.mm +++ b/Source/Modules/ControllerModules/KeyHandler.mm @@ -405,23 +405,29 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; } // NON-SWIFTIFIABLE -- (nullable InputState *)buildAssociatePhraseStateWithKey:(NSString *)key useVerticalMode:(BOOL)useVerticalMode +- (NSArray *)buildAssociatePhraseArrayWithKey:(NSString *)key { + NSMutableArray *array = [NSMutableArray array]; std::string cppKey = std::string(key.UTF8String); if (_languageModel->hasAssociatedPhrasesForKey(cppKey)) { std::vector phrases = _languageModel->associatedPhrasesForKey(cppKey); - NSMutableArray *array = [NSMutableArray array]; for (auto phrase : phrases) { NSString *item = [[NSString alloc] initWithUTF8String:phrase.c_str()]; [array addObject:item]; } - InputStateAssociatedPhrases *associatedPhrases = - [[InputStateAssociatedPhrases alloc] initWithCandidates:array useVerticalMode:useVerticalMode]; - return associatedPhrases; } - return nil; + return array; +} + +- (nullable InputState *)buildAssociatePhraseStateWithKey:(NSString *)key useVerticalMode:(BOOL)useVerticalMode +{ + NSArray *array = [self buildAssociatePhraseArrayWithKey:key]; + if (array == nil || [array count] == 0) + return nil; + else + return [[InputStateAssociatedPhrases alloc] initWithCandidates:array useVerticalMode:useVerticalMode]; } #pragma mark - 必須用 ObjCpp 處理的部分: Mandarin diff --git a/Source/Modules/ControllerModules/KeyHandler_States.swift b/Source/Modules/ControllerModules/KeyHandler_States.swift index 59e30932..db3abdcd 100644 --- a/Source/Modules/ControllerModules/KeyHandler_States.swift +++ b/Source/Modules/ControllerModules/KeyHandler_States.swift @@ -63,7 +63,7 @@ import Cocoa return newState } - // MARK: - 用以生成候選詞數組 + // MARK: - 用以生成候選詞數組及狀態 func _buildCandidateState( _ currentState: InputState.NotEmpty, @@ -80,6 +80,8 @@ import Cocoa return state } + // MARK: - 用以接收聯想詞數組且生成狀態 + // MARK: - 用以處理就地新增自訂語彙時的行為 func _handleMarkingState(