From a240da5297960dd7a6797e2b144f77d8418a0a0b Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Thu, 21 Apr 2022 15:49:17 +0800 Subject: [PATCH] KeyHandler // Let Front-Cursor mode select phrase when index == 0. --- Source/Modules/ControllerModules/KeyHandler.h | 1 + Source/Modules/ControllerModules/KeyHandler.mm | 5 +++++ Source/Modules/ControllerModules/KeyHandler_Misc.swift | 6 +++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Source/Modules/ControllerModules/KeyHandler.h b/Source/Modules/ControllerModules/KeyHandler.h index dd45b041..020bad09 100644 --- a/Source/Modules/ControllerModules/KeyHandler.h +++ b/Source/Modules/ControllerModules/KeyHandler.h @@ -74,6 +74,7 @@ struct BufferStatePackage - (BOOL)isPrintable:(UniChar)charCode; - (NSArray *)buildAssociatePhraseArrayWithKey:(NSString *)key; - (NSArray *)getCandidatesArray; +- (NSInteger)getKeyLengthAtIndexZero; - (NSInteger)getBuilderCursorIndex; - (NSInteger)getBuilderLength; - (NSInteger)getPackagedCursorIndex; diff --git a/Source/Modules/ControllerModules/KeyHandler.mm b/Source/Modules/ControllerModules/KeyHandler.mm index c9be6c67..97eb3053 100644 --- a/Source/Modules/ControllerModules/KeyHandler.mm +++ b/Source/Modules/ControllerModules/KeyHandler.mm @@ -623,6 +623,11 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; return candidatesArray; } +- (NSInteger)getKeyLengthAtIndexZero +{ + return [NSString stringWithUTF8String:_walkedNodes[0].node->currentKeyValue().value.c_str()].length; +} + #pragma mark - 威注音認為有必要單獨拿出來處理的部分,交給 Swift 則有些困難。 - (BOOL)isPrintable:(UniChar)charCode diff --git a/Source/Modules/ControllerModules/KeyHandler_Misc.swift b/Source/Modules/ControllerModules/KeyHandler_Misc.swift index b215d86b..0421a562 100644 --- a/Source/Modules/ControllerModules/KeyHandler_Misc.swift +++ b/Source/Modules/ControllerModules/KeyHandler_Misc.swift @@ -41,7 +41,11 @@ import Cocoa && (cursorIndex < getBuilderLength())) || cursorIndex == 0 { - cursorIndex += 1 + if cursorIndex == 0 && !mgrPrefs.setRearCursorMode { + cursorIndex += getKeyLengthAtIndexZero() + } else { + cursorIndex += 1 + } } return cursorIndex }