aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dmenu.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/dmenu.c b/dmenu.c
index 4a6ca3d..1d239c2 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -79,9 +79,9 @@ static char text[4096];
79static int cmdw = 0; 79static int cmdw = 0;
80static int promptw = 0; 80static int promptw = 0;
81static int ret = 0; 81static int ret = 0;
82static int cursor = 0;
83static int screen; 82static int screen;
84static unsigned int mw, mh; 83static unsigned int mw, mh;
84static unsigned int cursor = 0;
85static unsigned int numlockmask = 0; 85static unsigned int numlockmask = 0;
86static Bool running = True; 86static Bool running = True;
87static Display *dpy; 87static Display *dpy;
@@ -338,8 +338,8 @@ initfont(const char *fontstr) {
338void 338void
339kpress(XKeyEvent * e) { 339kpress(XKeyEvent * e) {
340 char buf[sizeof text]; 340 char buf[sizeof text];
341 int i, num; 341 int num;
342 unsigned int len; 342 unsigned int i, len;
343 KeySym ksym; 343 KeySym ksym;
344 344
345 len = strlen(text); 345 len = strlen(text);
@@ -381,6 +381,10 @@ kpress(XKeyEvent * e) {
381 case XK_J: 381 case XK_J:
382 ksym = XK_Return; 382 ksym = XK_Return;
383 break; 383 break;
384 case XK_k:
385 case XK_K:
386 text[cursor] = '\0';
387 break;
384 case XK_u: 388 case XK_u:
385 case XK_U: 389 case XK_U:
386 memmove(text, text + cursor, sizeof text - cursor + 1); 390 memmove(text, text + cursor, sizeof text - cursor + 1);
@@ -450,12 +454,12 @@ kpress(XKeyEvent * e) {
450 } 454 }
451 break; 455 break;
452 case XK_BackSpace: 456 case XK_BackSpace:
453 if(cursor > 0) { 457 if(cursor == 0)
454 for(i = 1; cursor - i > 0 && !IS_UTF8_1ST_CHAR(text[cursor - i]); i++); 458 return;
455 memmove(text + cursor - i, text + cursor, sizeof text - cursor + i); 459 for(i = 1; cursor - i > 0 && !IS_UTF8_1ST_CHAR(text[cursor - i]); i++);
456 cursor -= i; 460 memmove(text + cursor - i, text + cursor, sizeof text - cursor + i);
457 match(text); 461 cursor -= i;
458 } 462 match(text);
459 break; 463 break;
460 case XK_Delete: 464 case XK_Delete:
461 for(i = 1; cursor + i < len && !IS_UTF8_1ST_CHAR(text[cursor + i]); i++); 465 for(i = 1; cursor + i < len && !IS_UTF8_1ST_CHAR(text[cursor + i]); i++);
@@ -477,7 +481,7 @@ kpress(XKeyEvent * e) {
477 case XK_Escape: 481 case XK_Escape:
478 ret = 1; 482 ret = 1;
479 running = False; 483 running = False;
480 break; 484 return;
481 case XK_Home: 485 case XK_Home:
482 if(sel == item) { 486 if(sel == item) {
483 cursor = 0; 487 cursor = 0;
@@ -519,7 +523,7 @@ kpress(XKeyEvent * e) {
519 fprintf(stdout, "%s", sel->text); 523 fprintf(stdout, "%s", sel->text);
520 fflush(stdout); 524 fflush(stdout);
521 running = False; 525 running = False;
522 break; 526 return;
523 case XK_Right: 527 case XK_Right:
524 case XK_Down: 528 case XK_Down:
525 if(cursor < len) 529 if(cursor < len)