@@ -296,6 +296,10 @@ void ekg::ui::handle_erase(
296296 ekg::textbox_t &textbox,
297297 ekg::textbox_t ::cursor_t &cursor
298298) {
299+ if (cursor.a == cursor.b ) {
300+ return ;
301+ }
302+
299303 if (cursor.a .y == cursor.b .y ) {
300304 std::string line {textbox.text .at (cursor.a .y )};
301305 std::string concated {};
@@ -314,6 +318,7 @@ void ekg::ui::handle_erase(
314318
315319 cursor.b = cursor.a ;
316320 cursor.delta = cursor.a ;
321+ cursor.highest_char_index = cursor.a .x ;
317322
318323 return ;
319324 }
@@ -338,6 +343,7 @@ void ekg::ui::handle_erase(
338343
339344 cursor.b = cursor.a ;
340345 cursor.delta = cursor.a ;
346+ cursor.highest_char_index = cursor.a .x ;
341347}
342348
343349void ekg::ui::handle_insert (
@@ -358,6 +364,7 @@ void ekg::ui::handle_insert(
358364 cursor.a .y ++;
359365 cursor.a .x = 0 ;
360366 cursor.b = cursor.a ;
367+ cursor.highest_char_index = cursor.a .x ;
361368 return ;
362369 }
363370
@@ -375,6 +382,7 @@ void ekg::ui::handle_insert(
375382
376383 cursor.a .x += ekg::utf8_length (typed);
377384 cursor.b = cursor.a ;
385+ cursor.highest_char_index = cursor.a .x ;
378386}
379387
380388void ekg::ui::reload (
@@ -451,7 +459,7 @@ void ekg::ui::event(
451459
452460 switch (stage) {
453461 default : {
454- ekg::input_info_t & input {ekg::p_core->handler_input .input };
462+ ekg::input_info_t input {ekg::p_core->handler_input .input };
455463 ekg::vec2_t <float > interact {static_cast <ekg::vec2_t <float >>(input.interact )};
456464
457465 /* focus part */
@@ -567,13 +575,40 @@ void ekg::ui::event(
567575 return ;
568576 }
569577
570- /* logic of cursors, for handling lot of curosrs we will use only one loop for improve performance */
578+ /* *
579+ * logic of cursors:
580+ * for handling lot of cursors we will
581+ * use only one loop for improve performance
582+ **/
583+
584+ bool is_action_selected_all_fired {ekg::fired (" textbox-action-select-all" )};
585+ if (is_action_selected_all_fired) {
586+ size_t lines {textbox.text .length_of_lines ()};
587+ if (lines > 0 ) {
588+ lines -= 1 ;
589+ std::string last_line {textbox.text .at (lines)};
590+ textbox.widget .cursors .clear ();
591+ textbox.widget .cursors .push_back (
592+ {
593+ .a = {0 , 0 },
594+ .b = {ekg::utf8_length (last_line), lines}
595+ }
596+ );
597+ }
598+
599+ return ;
600+ }
601+
602+ bool is_action_copy {ekg::fired (" clipboard-copy" )};
603+ bool is_action_paste {ekg::fired (" clipboard-paste" )};
604+ bool is_action_cut {ekg::fired (" clipboard-cut" )};
571605
572606 bool is_action_erase_right_fired {ekg::fired (" textbox-action-erase-right" )};
573607 bool is_action_erase_left_fired {ekg::fired (" textbox-action-erase-left" )};
574608 bool is_action_erase_fired {is_action_erase_left_fired || is_action_erase_right_fired};
575609 bool is_action_selected_keybind_fired {ekg::fired (" textbox-action-select" )};
576610 bool is_action_selected_fired {};
611+ bool is_action_break_line_fired {ekg::fired (" textbox-action-break-line" )};
577612
578613 bool is_modifier_fired {ekg::fired (" textbox-action-modifier" )};
579614 bool is_left_fired {ekg::fired (" textbox-action-left" )};
@@ -586,9 +621,31 @@ void ekg::ui::event(
586621 bool is_modifier_down_fired {is_down_fired && is_modifier_fired};
587622 bool is_arrows_fired {is_left_fired || is_right_fired || is_up_fired || is_down_fired};
588623
589- bool is_textbox_action_break_line_fired {ekg::fired (" textbox-action-break-line" )};
624+ if (is_action_paste) {
625+ input.was_typed = true ;
626+ input.typed = ekg::p_core->p_platform_base ->get_clipboard_text ();
627+ }
628+
629+ std::string clipboard_builder {};
630+ if (is_action_cut) {
631+ input.was_typed = false ;
632+ }
590633
591- if (is_arrows_fired || is_action_erase_fired || input.was_typed || is_textbox_action_break_line_fired) {
634+ if (
635+ is_arrows_fired
636+ ||
637+ is_action_erase_fired
638+ ||
639+ input.was_typed
640+ ||
641+ is_action_break_line_fired
642+ ||
643+ is_action_copy
644+ ||
645+ is_action_cut
646+ ||
647+ is_action_paste
648+ ) {
592649 textbox.widget .set_cursor_static = true ;
593650 }
594651
@@ -605,8 +662,11 @@ void ekg::ui::event(
605662 ekg::vec2_t <float > cursor_pos {};
606663 std::string line {};
607664
665+ size_t cursors_size {textbox.widget .cursors .size ()};
666+ size_t cursor_count {};
608667
609668 for (ekg::textbox_t ::cursor_t &cursor : textbox.widget .cursors ) {
669+ cursor_count++;
610670 is_ab_equals = cursor.a == cursor.b ;
611671
612672 is_action_selected_fired = (is_arrows_fired && is_action_selected_keybind_fired) || (is_action_erase_fired && is_ab_equals);
@@ -810,15 +870,24 @@ void ekg::ui::event(
810870 }
811871 }
812872
813- if (is_action_erase_fired) {
873+ if (is_action_cut || is_action_copy) {
874+ clipboard_builder += textbox.text .read (
875+ cursor.a ,
876+ cursor.b
877+ )
878+ +
879+ (((cursors_size > 1 ) && !is_ab_equals && cursor_count != cursors_size) ? EKG_EOF_SYSTEM : " " );
880+ }
881+
882+ if (is_action_erase_fired || is_action_cut) {
814883 ekg::ui::handle_erase (textbox, cursor);
815884 }
816885
817- if (input.was_typed || is_textbox_action_break_line_fired ) {
886+ if (input.was_typed || is_action_break_line_fired ) {
818887 ekg::ui::handle_insert (
819888 textbox,
820889 cursor,
821- is_textbox_action_break_line_fired
890+ is_action_break_line_fired
822891 ? EKG_EOF_SYSTEM : input.typed
823892 );
824893 }
@@ -839,7 +908,11 @@ void ekg::ui::event(
839908 }
840909 }
841910
842- if (is_action_erase_fired || input.was_typed || is_textbox_action_break_line_fired) {
911+ if (is_action_cut || is_action_copy) {
912+ ekg::p_core->p_platform_base ->set_clipboard_text (clipboard_builder.c_str ());
913+ }
914+
915+ if (is_action_erase_fired || input.was_typed || is_action_break_line_fired) {
843916 ekg::ui::refresh_scroll_sizes (textbox);
844917 }
845918
0 commit comments