@@ -13,6 +13,7 @@ @implementation MACHView {
13
13
void (^_mouseUp_block)(NSEvent *);
14
14
void (^_scrollWheel_block)(NSEvent *);
15
15
void (^_magnify_block)(NSEvent *);
16
+ void (^_insertText_block)(NSEvent *, uint32_t );
16
17
NSTrackingArea *trackingArea;
17
18
}
18
19
@@ -59,6 +60,11 @@ - (void)setBlock_flagsChanged:(void (^)(NSEvent *))flagsChanged_block
59
60
_flagsChanged_block = flagsChanged_block;
60
61
}
61
62
63
+ - (void )setBlock_insertText : (void (^)(NSEvent *, uint32_t ))insertText_block
64
+ __attribute__((objc_direct)) {
65
+ _insertText_block = insertText_block;
66
+ }
67
+
62
68
- (void )setBlock_magnify : (void (^)(NSEvent *))magnify_block
63
69
__attribute__((objc_direct)) {
64
70
_magnify_block = magnify_block;
@@ -67,6 +73,37 @@ - (void)setBlock_magnify:(void (^)(NSEvent *))magnify_block
67
73
- (void )keyDown : (NSEvent *)event {
68
74
if (_keyDown_block)
69
75
_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
+ }
70
107
}
71
108
72
109
- (void )keyUp : (NSEvent *)event {
0 commit comments