Transfer ->

This commit is contained in:
Allen Webster 2020-05-01 17:58:01 -07:00
parent bd26b2afe4
commit 6454ffc264
1 changed files with 36 additions and 1 deletions

View File

@ -915,11 +915,46 @@ mac_toggle_fullscreen(void){
return(YES);
}
- (void)insertText:(NSString*)text{
u32 len = [characters length];
Scratch_Block scratch(mac_vars.tctx);
u16 *utf16 = push_array(scratch, u16, len);
[text getCharacters:utf16 range:NSMakeRange(0, len)];
String_Const_u16 str_16 = SCu16(utf16, len);
String_Const_u8 str_8 = string_u8_from_string_u16(&mac_vars.frame_arena, str_16).string;
for (i64 i = 0; i < str_8.size; i += 1){
if (str_8.str[i] == '\r'){
str_8.str[i] = '\n';
}
}
Input_Event *event = push_input_event(&mac_vars.frame_arena, &mac_vars.input_chunk.trans.event_list);
event->kind = InputEventKind_TextInsert;
event->text.string = str_8;
event->text.next_text = 0;
event->text.blocked = false;
if (mac_vars.active_text_input){
mac_vars.active_text_input->text.next_text = event;
} else if (mac_vars.active_key_stroke){
mac_vars.active_key_stroke->key.first_dependent_text = event;
}
mac_vars.active_text_input = event;
system_signal_step(0);
}
- (void)keyDown:(NSEvent*)event{
// NOTE(yuval): Process keyboard event
[self process_keyboard_event:event down:true];
[self interpretKeyEvents:[NSArray arrayWithObject:event]];
{
NSString *characters = [event characters];
u32 len = [characters length];
if (len > 0){
[self interpretKeyEvents:[NSArray arrayWithObject:event]];
}
}
#if 0
// NOTE(yuval): Process TextInsert event