From 55ef21312888cbfb9d449eee8f7958b74f85ac7c Mon Sep 17 00:00:00 2001 From: Physick <96335032+DegustatorPonos@users.noreply.github.com> Date: Fri, 10 Jul 2026 00:02:55 +0500 Subject: more work on an editor --- src/ui_elements/TextEditor.c | 8 +++++++- src/ui_elements/UI.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'src/ui_elements') diff --git a/src/ui_elements/TextEditor.c b/src/ui_elements/TextEditor.c index ebc8671..fa85443 100644 --- a/src/ui_elements/TextEditor.c +++ b/src/ui_elements/TextEditor.c @@ -68,11 +68,13 @@ bool AddSpaceDetermined(TextNode *base, size_t additional_space) { void AppendTextToNode(TextNode *base, char *new_text) { if (base == NULL || new_text == NULL) return; size_t len = strlen(base->text); + size_t new_len = strlen(new_text); /// >= and not > because it needs a \0 - if (len + strlen(new_text) >= base->cap) { + if (len + new_len >= base->cap) { if (!AddSpace(base)) return; } strcpy(base->text + len, new_text); + base->len += new_len; } TextArea *CreateTextArea() { @@ -367,6 +369,10 @@ void HandleKeyboard(TextArea *ta) { if (IsKeyPressedFix(KEY_RIGHT)) MoveCursorRight(ta); if (IsKeyPressedFix(KEY_DOWN)) MoveCursorDown(ta); if (IsKeyPressedFix(KEY_UP)) MoveCursorUp(ta); + if (IsKeyPressedFix(KEY_TAB)) { + for (int i = 0; i < TAB_WIDTH; i++) + InsertChar(ta, ' '); + }; if (IsKeyPressedFix(KEY_HOME)) MoveCursorHome(ta); if (IsKeyPressedFix(KEY_END)) MoveCursorEnd(ta); diff --git a/src/ui_elements/UI.h b/src/ui_elements/UI.h index 779290f..eaf17e8 100644 --- a/src/ui_elements/UI.h +++ b/src/ui_elements/UI.h @@ -5,6 +5,7 @@ #define UI_ELEMENTS_H static const float SCROLL_SENC = 10; +static const float TAB_WIDTH = 4; void DrawRecBordered(Rectangle rec, Color bg, Color border_color, int border_width); void DrawTextInRec(Rectangle rec, char *text, Font *font, int height, Color color, float padding, int *scroll); -- cgit v1.3