summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/tk/text.c20
1 files changed, 20 insertions, 0 deletions
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;
}