Skip to content

Commit 98aa846

Browse files
committed
[fix] glitches on typing/erase
1 parent 1d2d9b8 commit 98aa846

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

cmake/properties.cmake

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,19 @@ endif()
3737

3838
if(WIN32 OR EKG_FORCE_WINDOWS)
3939
set(LIBRARY_OUTPUT_PATH "../lib/windows/")
40-
set(PLATFORM "windows")
40+
set(PLATFORM "windows")
41+
add_compile_definitions(EKG_EOF_SYSTEM="\r\n")
4142
elseif(ANDROID OR EKG_FORCE_ANDROID)
4243
set(LIBRARY_OUTPUT_PATH "${ANDROID_ABI}/")
43-
set(PLATFORM "${ANDROID_ABI}")
44+
set(PLATFORM "${ANDROID_ABI}")
45+
add_compile_definitions(EKG_EOF_SYSTEM="\n")
4446
elseif(EKG_EMSCRIPTEN_BUILD_TYPE)
4547
set(LIBRARY_OUTPUT_PATH "../lib/linux-wasm/")
46-
set(PLATFORM "linux-wasm")
48+
set(PLATFORM "linux-wasm")
49+
add_compile_definitions(EKG_EOF_SYSTEM="\n")
4750
elseif(LINUX OR EKG_FORCE_LINUX)
48-
# WSL is not detected as Linux-based OS, same you use a Linux kernel-based distribution.
51+
# WSL is not detected as Linux-kernel based OS; force is necessary ><
4952
set(LIBRARY_OUTPUT_PATH "../lib/linux/")
50-
set(PLATFORM "linux")
53+
set(PLATFORM "linux")
54+
add_compile_definitions(EKG_EOF_SYSTEM="\n")
5155
endif()

src/io/utf.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ size_t ekg::utf8_split_endings(
399399
return new_lines_count;
400400
}
401401

402-
void ekg::utf8_concat(
402+
void ekg:: utf8_concat(
403403
std::string &string,
404404
const ekg::vec4_t<std::size_t> &stride,
405405
std::string &concated

src/ui/textbox/widget.cpp

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)