From 6d43b932c0af090dc4cb89ce0e494c4cfd3c4f7d Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Fri, 06 Aug 2021 19:34:17 -0400 Subject: tk: Handle Backspace and Delete keys in text --- diff --git a/src/tk/text.c b/src/tk/text.c index 2a77691..1cbeb50 100644 --- a/src/tk/text.c +++ b/src/tk/text.c @@ -64,6 +64,7 @@ _mftk_text_key_event(struct mftk_widget *w, SDL_Event *e) { struct mftk_text *t = (struct mftk_text *) w; int len; + int i; switch (e->type) { case SDL_KEYDOWN: @@ -87,6 +88,25 @@ _mftk_text_key_event(struct mftk_widget *w, SDL_Event *e) case SDLK_END: t->cur = strlen(t->val); break; + case SDLK_BACKSPACE: + if (t->cur <= 0) { + break; + } + --t->cur; + len = strlen(t->val); + for (i = t->cur; i < len; ++i) { + t->val[i] = t->val[i + 1]; + } + break; + case SDLK_DELETE: + len = strlen(t->val); + if (t->cur >= len) { + break; + } + for (i = t->cur; i < len; ++i) { + t->val[i] = t->val[i + 1]; + } + break; default: break; } -- cgit v0.9.1