From 6454ffc264b51cc4197e7291c18bcb0c9382d30a Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Fri, 1 May 2020 17:58:01 -0700 Subject: [PATCH] Transfer -> --- platform_mac/mac_4ed.mm | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/platform_mac/mac_4ed.mm b/platform_mac/mac_4ed.mm index a0e156e7..43c1c360 100644 --- a/platform_mac/mac_4ed.mm +++ b/platform_mac/mac_4ed.mm @@ -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