Skip to content

Commit 236d1f0

Browse files
foxnneemidoots
authored andcommitted
Add insertText callback, this is responsible for input text
1 parent 401c0be commit 236d1f0

4 files changed

+1099
-444
lines changed

MACHView.m

+37
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ @implementation MACHView {
1313
void (^_mouseUp_block)(NSEvent *);
1414
void (^_scrollWheel_block)(NSEvent *);
1515
void (^_magnify_block)(NSEvent *);
16+
void (^_insertText_block)(NSEvent *, uint32_t);
1617
NSTrackingArea *trackingArea;
1718
}
1819

@@ -59,6 +60,11 @@ - (void)setBlock_flagsChanged:(void (^)(NSEvent *))flagsChanged_block
5960
_flagsChanged_block = flagsChanged_block;
6061
}
6162

63+
- (void)setBlock_insertText:(void (^)(NSEvent *, uint32_t))insertText_block
64+
__attribute__((objc_direct)) {
65+
_insertText_block = insertText_block;
66+
}
67+
6268
- (void)setBlock_magnify:(void (^)(NSEvent *))magnify_block
6369
__attribute__((objc_direct)) {
6470
_magnify_block = magnify_block;
@@ -67,6 +73,37 @@ - (void)setBlock_magnify:(void (^)(NSEvent *))magnify_block
6773
- (void)keyDown:(NSEvent *)event {
6874
if (_keyDown_block)
6975
_keyDown_block(event);
76+
77+
[self interpretKeyEvents:@[ event ]];
78+
}
79+
80+
- (void)insertText:(id)string {
81+
NSString *characters;
82+
NSEvent *event = [NSApp currentEvent];
83+
84+
if ([string isKindOfClass:[NSAttributedString class]])
85+
characters = [string string];
86+
else
87+
characters = (NSString *)string;
88+
89+
NSRange range = NSMakeRange(0, [characters length]);
90+
while (range.length) {
91+
uint32_t codepoint = 0;
92+
93+
if ([characters getBytes:&codepoint
94+
maxLength:sizeof(codepoint)
95+
usedLength:NULL
96+
encoding:NSUTF32StringEncoding
97+
options:0
98+
range:range
99+
remainingRange:&range]) {
100+
if (codepoint >= 0xf700 && codepoint <= 0xf7ff) {
101+
continue;
102+
}
103+
if (_insertText_block)
104+
_insertText_block(event, codepoint);
105+
}
106+
}
70107
}
71108

72109
- (void)keyUp:(NSEvent *)event {

0 commit comments

Comments
 (0)