@@ -326,6 +326,28 @@ void ekg::ui::handle_erase(
326326 cursor.delta = cursor.a ;
327327}
328328
329+ void ekg::ui::handle_insert (
330+ ekg::textbox_t &textbox,
331+ ekg::textbox_t ::cursor_t &cursor,
332+ std::string_view typed
333+ ) {
334+ if (cursor.a != cursor.b ) {
335+ ekg::ui::handle_erase (textbox, cursor);
336+ }
337+
338+ std::string line {textbox.text .at (cursor.a .y )};
339+
340+ line.insert (
341+ line.begin () + cursor.a .x ,
342+ typed.begin (),
343+ typed.end ()
344+ );
345+
346+ textbox.text .set (cursor.a .y , line);
347+ cursor.a .x += ekg::utf8_length (typed);
348+ cursor.b = cursor.a ;
349+ }
350+
329351void ekg::ui::reload (
330352 ekg::property_t &property,
331353 ekg::textbox_t &textbox
@@ -513,7 +535,7 @@ void ekg::ui::event(
513535 );
514536 }
515537
516- if (!input.was_typed ) {
538+ if (!input.was_typed && !input. was_pressed ) {
517539 return ;
518540 }
519541
@@ -534,7 +556,7 @@ void ekg::ui::event(
534556 bool is_down_fired {ekg::fired (" textbox-action-down" )};
535557 bool is_modifier_down_fired {is_down_fired && is_modifier_fired};
536558
537- if (is_left_fired || is_right_fired || is_up_fired || is_down_fired || is_action_erase_fired) {
559+ if (is_left_fired || is_right_fired || is_up_fired || is_down_fired || is_action_erase_fired || input. was_typed ) {
538560 textbox.widget .set_cursor_static = true ;
539561 }
540562
@@ -551,6 +573,7 @@ void ekg::ui::event(
551573 ekg::vec2_t <float > cursor_pos {};
552574 std::string line {};
553575
576+ ekg_log_low_level (input.was_typed );
554577
555578 for (ekg::textbox_t ::cursor_t &cursor : textbox.widget .cursors ) {
556579 is_ab_equals = cursor.a == cursor.b ;
@@ -769,6 +792,10 @@ void ekg::ui::event(
769792 if (is_action_erase_fired) {
770793 ekg::ui::handle_erase (textbox, cursor);
771794 }
795+
796+ if (input.was_typed ) {
797+ ekg::ui::handle_insert (textbox, cursor, input.typed );
798+ }
772799 }
773800
774801 break ;
0 commit comments