-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tweak.xm
69 lines (54 loc) · 2.19 KB
/
Tweak.xm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <CoreFoundation/CFString.h>
@interface UIKeyboardImpl
- (NSString *)hankana:(NSString *)string;
- (void)setCandidates:(id)arg1;
- (id)inputStringFromPhraseBoundary;
@end
@interface TIKeyboardCandidate
@end
@interface TIKeyboardCandidateResultSet
- (NSArray *)candidates;
- (BOOL)hasCandidates;
+ (id)setWithCandidates:(id)arg1;
- (TIKeyboardCandidate *)defaultCandidate;
- (NSArray *)sortMethods;
- (void)setGeneratedCandidateCount:(unsigned long long)arg1;
- (void)setDefaultCandidate:(TIKeyboardCandidate *)arg1;
- (void)setSortMethods:(NSArray *)arg1;
@end
@interface TIKeyboardCandidateSingle
+ (id)candidateWithCandidate:(id)arg1 forInput:(id)arg2;
@end
%hook UIKeyboardImpl
%new
- (NSString *)hankana:(NSString *)string {
NSMutableString *mutableString = [string mutableCopy];
CFStringTransform((CFMutableStringRef)mutableString, NULL, kCFStringTransformHiraganaKatakana, NO);
CFStringTransform((CFMutableStringRef)mutableString, NULL, kCFStringTransformFullwidthHalfwidth, NO);
return [mutableString precomposedStringWithCanonicalMapping];
}
- (void)setCandidates:(TIKeyboardCandidateResultSet *)resultSet {
if ([resultSet hasCandidates]) {
NSString *input = [self inputStringFromPhraseBoundary];
if (input) {
NSString *hankanaInput = [self hankana:input];
if (![input isEqualToString:hankanaInput]) {
NSMutableArray *mutableCandidates = [NSMutableArray arrayWithArray:[resultSet candidates]];
int index = 2;
if ([mutableCandidates count] <= 2) {
index = [mutableCandidates count];
}
TIKeyboardCandidateSingle *hankakuCandidate = [objc_getClass("TIKeyboardCandidateSingle") candidateWithCandidate:hankanaInput forInput:input];
[mutableCandidates insertObject:hankakuCandidate atIndex:index];
NSArray *sortMethods = [NSArray arrayWithArray:[resultSet sortMethods]];
TIKeyboardCandidate *defaultCandidate = [resultSet defaultCandidate];
resultSet = [objc_getClass("TIKeyboardCandidateResultSet") setWithCandidates:[NSArray arrayWithArray:mutableCandidates]];
[resultSet setGeneratedCandidateCount:[[resultSet candidates] count]];
[resultSet setSortMethods:sortMethods];
[resultSet setDefaultCandidate:defaultCandidate];
}
}
}
%orig;
}
%end