From fe926ba646bb580f4b986501e524513f10ea6a32 Mon Sep 17 00:00:00 2001 From: dongyuwei Date: Wed, 17 Feb 2021 21:41:37 +0800 Subject: [PATCH] partial fix issues/100 --- Tests/TestConversionEngine.mm | 7 +++++-- src/AnnotationWinController.m | 2 +- src/ConversionEngine.mm | 2 +- src/InputController.mm | 6 +++++- src/main.mm | 5 ++--- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Tests/TestConversionEngine.mm b/Tests/TestConversionEngine.mm index fdba340..5c8d858 100644 --- a/Tests/TestConversionEngine.mm +++ b/Tests/TestConversionEngine.mm @@ -141,12 +141,15 @@ - (void)testGetPinyinCandidates { XCTAssertTrue(candidates.count == 4); NSArray *words3 = [candidates subarrayWithRange:NSMakeRange(0, 3)]; XCTAssertTrue([[words3 componentsJoinedByString:@";"] isEqualToString:@"xihongshi;西红柿;tomato"]); - + NSArray *candidates2 = [self.engine getCandidates:@"xhs"]; XCTAssertTrue(candidates2.count == 26); NSArray *words = [candidates2 subarrayWithRange:NSMakeRange(0, 26)]; XCTAssertTrue([[words componentsJoinedByString:@";"] - isEqualToString:@"xhs;新华社;Xinhua News Agency;西红柿;tomato;CL:隻|只;循环赛;round-robin tournament;新化市;Xinhua city in Hunan;新会市;Xinhui city in Guangdong;消火栓;fire hydrant;猩红色;scarlet (color);兴化市;Xinghua county level city in Taizhou 泰州;蟹黄水;crab roe;crab spawn;(used for crab meat in general);血红素;hemoglobin;须后水;aftershave"]); + isEqualToString: + @"xhs;新华社;Xinhua News Agency;西红柿;tomato;CL:隻|只;循环赛;round-robin tournament;新化市;Xinhua city in Hunan;新会市;Xinhui " + @"city in Guangdong;消火栓;fire hydrant;猩红色;scarlet (color);兴化市;Xinghua county level city in Taizhou 泰州;蟹黄水;crab " + @"roe;crab spawn;(used for crab meat in general);血红素;hemoglobin;须后水;aftershave"]); } @end diff --git a/src/AnnotationWinController.m b/src/AnnotationWinController.m index ce9e8b3..b9f244d 100644 --- a/src/AnnotationWinController.m +++ b/src/AnnotationWinController.m @@ -25,7 +25,7 @@ - (void)awakeFromNib { // Make sure panel can float over full screen apps self.panel.collectionBehavior = NSWindowCollectionBehaviorCanJoinAllSpaces; - + [self.panel setStyleMask:NSWindowStyleMaskBorderless]; [self performSelector:@selector(hideWindow) withObject:nil afterDelay:0.01]; diff --git a/src/ConversionEngine.mm b/src/ConversionEngine.mm index 086f784..1716ccb 100644 --- a/src/ConversionEngine.mm +++ b/src/ConversionEngine.mm @@ -139,7 +139,7 @@ - (NSArray *)sortByDamerauLevenshteinDistance:(NSArray *)original inputText:(NSS for (NSString *word in original) { NSUInteger distance = [text mdc_levenshteinDistanceTo:word]; if (distance <= 3) { // Max edit distance: 3 - [mutableArray addObject:@{ @"w" : word, @"d" : @(distance) }]; + [mutableArray addObject:@{@"w" : word, @"d" : @(distance)}]; } } NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"d" ascending:YES]; diff --git a/src/InputController.mm b/src/InputController.mm index 90de96f..55cf023 100644 --- a/src/InputController.mm +++ b/src/InputController.mm @@ -191,8 +191,12 @@ - (void)commitComposition:(id)sender { text = [self originalBuffer]; } BOOL commitWordWithSpace = [preference boolForKey:@"commitWordWithSpace"]; + if (commitWordWithSpace && text.length > 0) { - text = [NSString stringWithFormat:@"%@ ", text]; + char firstChar = [text characterAtIndex:0]; + if (![[NSCharacterSet decimalDigitCharacterSet] characterIsMember:firstChar]) { + text = [NSString stringWithFormat:@"%@ ", text]; + } } [sender insertText:text replacementRange:NSMakeRange(NSNotFound, NSNotFound)]; diff --git a/src/main.mm b/src/main.mm index 34f5a6a..5d97604 100644 --- a/src/main.mm +++ b/src/main.mm @@ -56,11 +56,10 @@ void deactivateInputSource() { void initPreference() { preference = [NSUserDefaults standardUserDefaults]; - NSDictionary *defaultPrefs = @{ @"commitWordWithSpace" : @YES, @"showTranslation" : @YES }; + NSDictionary *defaultPrefs = @{@"commitWordWithSpace" : @YES, @"showTranslation" : @YES}; [preference registerDefaults:defaultPrefs]; } - int main(int argc, char *argv[]) { if (argc > 1 && !strcmp("--install", argv[1])) { registerInputSource(); @@ -84,7 +83,7 @@ int main(int argc, char *argv[]) { [[NSBundle mainBundle] loadNibNamed:@"AnnotationWindow" owner:[NSApplication sharedApplication] topLevelObjects:nil]; [[NSBundle mainBundle] loadNibNamed:@"PreferencesMenu" owner:[NSApplication sharedApplication] topLevelObjects:nil]; - + initPreference(); [[WebServer sharedServer] start];