@@ -335,15 +335,31 @@ void ekg::ui::handle_insert(
335335 ekg::ui::handle_erase (textbox, cursor);
336336 }
337337
338+ if (typed == EKG_EOF_SYSTEM) {
339+ std::string line {textbox.text .at (cursor.a .y )};
340+
341+ textbox.text .set (cursor.a .y , ekg::utf8_substr (line, 0 , cursor.a .x ));
342+ textbox.text .insert (cursor.a .y , ekg::utf8_substr (line, cursor.a .x , UINT32_MAX));
343+
344+ cursor.a .y ++;
345+ cursor.a .x = 0 ;
346+ cursor.b = cursor.a ;
347+
348+ return ;
349+ }
350+
351+ size_t byte_pos {};
338352 std::string line {textbox.text .at (cursor.a .y )};
353+ ekg::utf8_find_byte_pos_by_utf_pos (line, cursor.a .x , byte_pos);
339354
340355 line.insert (
341- line.begin () + cursor. a . x ,
356+ line.begin () + byte_pos ,
342357 typed.begin (),
343358 typed.end ()
344359 );
345360
346361 textbox.text .set (cursor.a .y , line);
362+
347363 cursor.a .x += ekg::utf8_length (typed);
348364 cursor.b = cursor.a ;
349365}
@@ -544,7 +560,8 @@ void ekg::ui::event(
544560 bool is_action_erase_right_fired {ekg::fired (" textbox-action-erase-right" )};
545561 bool is_action_erase_left_fired {ekg::fired (" textbox-action-erase-left" )};
546562 bool is_action_erase_fired {is_action_erase_left_fired || is_action_erase_right_fired};
547- bool is_action_selected_fired {ekg::fired (" textbox-action-select" )};
563+ bool is_action_selected_keybind_fired {ekg::fired (" textbox-action-select" )};
564+ bool is_action_selected_fired {};
548565
549566 bool is_modifier_fired {ekg::fired (" textbox-action-modifier" )};
550567 bool is_left_fired {ekg::fired (" textbox-action-left" )};
@@ -555,8 +572,11 @@ void ekg::ui::event(
555572 bool is_modifier_up_fired {is_up_fired && is_modifier_fired};
556573 bool is_down_fired {ekg::fired (" textbox-action-down" )};
557574 bool is_modifier_down_fired {is_down_fired && is_modifier_fired};
575+ bool is_arrows_fired {is_left_fired || is_right_fired || is_up_fired || is_down_fired};
576+
577+ bool is_textbox_action_break_line_fired {ekg::fired (" textbox-action-break-line" )};
558578
559- if (is_left_fired || is_right_fired || is_up_fired || is_down_fired || is_action_erase_fired || input.was_typed ) {
579+ if (is_arrows_fired || is_action_erase_fired || input.was_typed || is_textbox_action_break_line_fired ) {
560580 textbox.widget .set_cursor_static = true ;
561581 }
562582
@@ -573,12 +593,10 @@ void ekg::ui::event(
573593 ekg::vec2_t <float > cursor_pos {};
574594 std::string line {};
575595
576- ekg_log_low_level (input.was_typed );
577-
578596 for (ekg::textbox_t ::cursor_t &cursor : textbox.widget .cursors ) {
579597 is_ab_equals = cursor.a == cursor.b ;
580598
581- is_action_selected_fired = is_action_selected_fired || (is_action_erase_fired && is_ab_equals);
599+ is_action_selected_fired = (is_arrows_fired && is_action_selected_keybind_fired) || (is_action_erase_fired && is_ab_equals);
582600 is_left_fired = is_left_fired || (is_action_erase_left_fired && is_ab_equals);
583601 is_right_fired = is_right_fired || (is_action_erase_right_fired && is_ab_equals);
584602
@@ -793,8 +811,13 @@ void ekg::ui::event(
793811 ekg::ui::handle_erase (textbox, cursor);
794812 }
795813
796- if (input.was_typed ) {
797- ekg::ui::handle_insert (textbox, cursor, input.typed );
814+ if (input.was_typed || is_textbox_action_break_line_fired) {
815+ ekg::ui::handle_insert (
816+ textbox,
817+ cursor,
818+ is_textbox_action_break_line_fired
819+ ? EKG_EOF_SYSTEM : input.typed
820+ );
798821 }
799822 }
800823
0 commit comments