Skip to content

Commit

Permalink
processing capitalized input properly
Browse files Browse the repository at this point in the history
  • Loading branch information
dongyuwei committed Jun 30, 2019
1 parent c7ef880 commit 325d263
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions src/InputController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,10 @@ - (void)setOriginalBuffer:(NSString *)input {

- (void)showPreeditString:(NSString *)input {
NSDictionary *attrs = [self markForStyle:kTSMHiliteSelectedRawText atRange:NSMakeRange(0, [input length])];
NSAttributedString *attrString;

NSString *originalBuff = [NSString stringWithString:[self originalBuffer]];
if ([[input lowercaseString] hasPrefix:[originalBuff lowercaseString]]) {
attrString = [[NSAttributedString alloc]
initWithString:[NSString stringWithFormat:@"%@%@", originalBuff, [input substringFromIndex:originalBuff.length]]
attributes:attrs];
} else {
attrString = [[NSAttributedString alloc] initWithString:input attributes:attrs];
}
NSString *originalBuff = [self originalBuffer];
NSAttributedString *attrString = [[NSAttributedString alloc]
initWithString:[NSString stringWithFormat:@"%@%@", originalBuff, [input substringFromIndex:originalBuff.length]]
attributes:attrs];

[_currentClient setMarkedText:attrString
selectionRange:NSMakeRange(input.length, 0)
Expand All @@ -281,7 +275,8 @@ - (void)appendToComposedBuffer:(NSString *)input {
}

- (NSArray *)candidates:(id)sender {
NSString *buffer = [[self originalBuffer] lowercaseString];
NSString *originalInput = [self originalBuffer];
NSString *buffer = [originalInput lowercaseString];
NSMutableArray *result = [[NSMutableArray alloc] init];

if (buffer && buffer.length > 0) {
Expand Down Expand Up @@ -309,8 +304,13 @@ - (NSArray *)candidates:(id)sender {
[result insertObject:buffer atIndex:0];
}

_candidates = [NSMutableArray arrayWithArray:result];
return [NSArray arrayWithArray:result];
NSMutableArray *result2 = [[NSMutableArray alloc] init];
for (NSString *word in result) {
// case sensitive input
[result2 addObject:[NSString stringWithFormat:@"%@%@", originalInput, [word substringFromIndex:originalInput.length]]];
}
_candidates = [NSMutableArray arrayWithArray:result2];
return [NSArray arrayWithArray:result2];
}

- (NSMutableArray *)queryTrie:(NSString *)buffer {
Expand Down Expand Up @@ -370,13 +370,7 @@ - (void)candidateSelected:(NSAttributedString *)candidateString {
}

- (void)_updateComposedBuffer:(NSAttributedString *)candidateString {
NSString *originalBuff = [NSString stringWithString:[self originalBuffer]];
NSString *composed = [candidateString string];
if ([composed hasPrefix:[originalBuff lowercaseString]]) {
[self setComposedBuffer:[NSString stringWithFormat:@"%@%@", originalBuff, [composed substringFromIndex:originalBuff.length]]];
} else {
[self setComposedBuffer:composed];
}
[self setComposedBuffer:[candidateString string]];
}

- (void)activateServer:(id)sender {
Expand Down

0 comments on commit 325d263

Please sign in to comment.