@@ -464,21 +464,28 @@ void ekg::ui::event(
464
464
bool is_up_fired {ekg::fired (" textbox-action-up" )};
465
465
bool is_modifier_up_fired {is_up_fired && ekg::fired (" textbox-action-modifier-up" )};
466
466
bool is_down_fired {ekg::fired (" textbox-action-down" )};
467
- bool is_modifier_down_fired {ekg::fired (" textbox-action-modifier-down" )};
467
+ bool is_modifier_down_fired {is_down_fired && ekg::fired (" textbox-action-modifier-down" )};
468
468
bool is_action_selected_fired {is_modifier_down_fired && ekg::fired (" textbox-action-select" )};
469
469
470
- if (! is_left_fired && ! is_right_fired && ! is_up_fired && ! is_down_fired) {
470
+ if (is_left_fired || is_right_fired || is_up_fired || is_down_fired) {
471
471
textbox.widget .set_cursor_static = true ;
472
472
}
473
473
474
474
bool is_ab_equals {};
475
475
bool is_ab_delta_equals {};
476
476
bool is_bounding {};
477
477
478
+ size_t utf_position_count {};
479
+ size_t utf_sequence_size {};
480
+ size_t new_cursor_byte_pos {};
481
+ size_t cursor_byte_pos {};
478
482
size_t text_total_lines {textbox.text .length_of_lines ()};
483
+ size_t byte_pos {};
479
484
480
485
ekg::rect_t <float > &rect_abs {ekg::ui::get_abs_rect (property, textbox.rect )};
481
486
ekg::vec2_t <float > cursor_pos {};
487
+
488
+ std::string line {};
482
489
std::sregex_iterator end {};
483
490
484
491
for (ekg::textbox_t ::cursor_t &cursor : textbox.widget .cursors ) {
@@ -495,15 +502,45 @@ void ekg::ui::event(
495
502
}
496
503
}
497
504
498
- if (is_modifier_left_fired) {
499
- std::string line {textbox.text .at (cursor.a .y )};
500
- std::sregex_iterator it (
505
+ if (
506
+ is_modifier_left_fired
507
+ &&
508
+ ekg::utf8_find_byte_pos_by_utf_pos (
509
+ (line = textbox.text .at (cursor.a .y )),
510
+ cursor.a .x ,
511
+ cursor_byte_pos
512
+ )
513
+ ) {
514
+ std::sregex_iterator iterator (
501
515
line.begin (),
502
- line.end () ,
516
+ line.begin () + cursor_byte_pos ,
503
517
textbox.regex_operations [ekg::textbox_t ::operation::modifier_left]
504
518
);
505
519
506
- std::smatch j = *it;
520
+ new_cursor_byte_pos = UINT64_MAX;
521
+ std::sregex_iterator end {};
522
+ for (auto it = iterator; it != end; it++) {
523
+ std::smatch j = *it;
524
+ new_cursor_byte_pos = j.position ();
525
+ ekg_log_low_level (new_cursor_byte_pos << " " << j.prefix ().str ())
526
+ }
527
+
528
+ if (new_cursor_byte_pos != UINT64_MAX) {
529
+ byte_pos = new_cursor_byte_pos;
530
+ utf_position_count = 0 ;
531
+ while (byte_pos < cursor_byte_pos) {
532
+ char &char8 {line.at (byte_pos)};
533
+ utf_sequence_size = 1 ;
534
+ utf_sequence_size += ((char8 & 0xE0 ) == 0xC0 );
535
+ utf_sequence_size += 2 * ((char8 & 0xF0 ) == 0xE0 );
536
+ utf_sequence_size += 3 * ((char8 & 0xF8 ) == 0xF0 );
537
+ byte_pos += utf_sequence_size;
538
+ utf_position_count++;
539
+ }
540
+
541
+ ekg_log_low_level (utf_position_count)
542
+ cursor.a .x -= utf_position_count;
543
+ }
507
544
}
508
545
509
546
cursor.highest_char_index = cursor.a .x ;
@@ -522,6 +559,49 @@ void ekg::ui::event(
522
559
}
523
560
}
524
561
562
+ if (
563
+ is_modifier_right_fired
564
+ &&
565
+ ekg::utf8_find_byte_pos_by_utf_pos (
566
+ (line = textbox.text .at (cursor.b .y )),
567
+ cursor.b .x ,
568
+ cursor_byte_pos
569
+ )
570
+ ) {
571
+ std::sregex_iterator iterator (
572
+ line.begin () + cursor_byte_pos,
573
+ line.end (),
574
+ textbox.regex_operations [ekg::textbox_t ::operation::modifier_right]
575
+ );
576
+
577
+ new_cursor_byte_pos = UINT64_MAX;
578
+ std::sregex_iterator end {};
579
+ for (auto it = iterator; it != end; it++) {
580
+ std::smatch j = *it;
581
+ new_cursor_byte_pos = cursor_byte_pos + j.position ();
582
+ ekg_log_low_level (new_cursor_byte_pos << " v " << j.prefix ().str ())
583
+ break ;
584
+ }
585
+
586
+ if (new_cursor_byte_pos != UINT64_MAX) {
587
+ byte_pos = cursor_byte_pos;
588
+ utf_position_count = 0 ;
589
+ ekg_log_low_level (byte_pos << " x " << new_cursor_byte_pos)
590
+ while (byte_pos < new_cursor_byte_pos) {
591
+ char &char8 {line.at (byte_pos)};
592
+ utf_sequence_size = 1 ;
593
+ utf_sequence_size += ((char8 & 0xE0 ) == 0xC0 );
594
+ utf_sequence_size += 2 * ((char8 & 0xF0 ) == 0xE0 );
595
+ utf_sequence_size += 3 * ((char8 & 0xF8 ) == 0xF0 );
596
+ byte_pos += utf_sequence_size;
597
+ utf_position_count++;
598
+ }
599
+
600
+ ekg_log_low_level (utf_position_count)
601
+ cursor.b .x += utf_position_count;
602
+ }
603
+ }
604
+
525
605
cursor.highest_char_index = cursor.b .x ;
526
606
cursor.a = cursor.b ;
527
607
cursor.delta = cursor.a ;
0 commit comments