Skip to content

Commit

Permalink
partial fix issues/100
Browse files Browse the repository at this point in the history
  • Loading branch information
dongyuwei committed Feb 17, 2021
1 parent a906edb commit fe926ba
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
7 changes: 5 additions & 2 deletions Tests/TestConversionEngine.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/AnnotationWinController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion src/ConversionEngine.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
6 changes: 5 additions & 1 deletion src/InputController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
Expand Down
5 changes: 2 additions & 3 deletions src/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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];
Expand Down

0 comments on commit fe926ba

Please sign in to comment.