applied Ramils patch
504b797b
1 file(s) · +21 −10
| 19 | 19 | #define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH)) |
|
| 20 | 20 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) |
|
| 21 | 21 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) |
|
| 22 | + | #define IS_UTF8_1ST_CHAR(c) ((((c) & 0xc0) == 0xc0) || !((c) & 0x80)) |
|
| 22 | 23 | ||
| 23 | 24 | /* enums */ |
|
| 24 | 25 | enum { ColFG, ColBG, ColLast }; |
|
| 360 | 361 | void |
|
| 361 | 362 | kpress(XKeyEvent * e) { |
|
| 362 | 363 | char buf[sizeof text]; |
|
| 363 | - | int i, num; |
|
| 364 | + | int i, num, off; |
|
| 364 | 365 | unsigned int len; |
|
| 365 | 366 | KeySym ksym; |
|
| 366 | 367 | ||
| 475 | 476 | break; |
|
| 476 | 477 | case XK_BackSpace: |
|
| 477 | 478 | if(cursor > 0) { |
|
| 478 | - | memmove(text + cursor - 1, text + cursor, sizeof text - cursor + 1); |
|
| 479 | - | cursor--; |
|
| 479 | + | off = 1; |
|
| 480 | + | while(cursor > off && !IS_UTF8_1ST_CHAR(text[cursor - off])) |
|
| 481 | + | off++; |
|
| 482 | + | memmove(text + cursor - off, text + cursor, sizeof text - cursor + off); |
|
| 483 | + | cursor -= off; |
|
| 480 | 484 | match(text); |
|
| 481 | 485 | } |
|
| 482 | 486 | break; |
|
| 483 | 487 | case XK_Delete: |
|
| 484 | - | memmove(text + cursor, text + cursor + 1, sizeof text - cursor); |
|
| 488 | + | off = 1; |
|
| 489 | + | while(cursor + off < sizeof text - 1 && !IS_UTF8_1ST_CHAR(text[cursor + off])) |
|
| 490 | + | off++; |
|
| 491 | + | memmove(text + cursor, text + cursor + off, sizeof text - cursor); |
|
| 485 | 492 | match(text); |
|
| 486 | 493 | break; |
|
| 487 | 494 | case XK_End: |
|
| 517 | 524 | calcoffsets(); |
|
| 518 | 525 | } |
|
| 519 | 526 | } |
|
| 520 | - | else if(cursor > 0) |
|
| 521 | - | cursor--; |
|
| 522 | - | else |
|
| 527 | + | else if(cursor > 0) { |
|
| 528 | + | do { |
|
| 529 | + | cursor--; |
|
| 530 | + | } while(cursor > 0 && !IS_UTF8_1ST_CHAR(text[cursor])); |
|
| 531 | + | } else |
|
| 523 | 532 | return; |
|
| 524 | 533 | break; |
|
| 525 | 534 | case XK_Next: |
|
| 544 | 553 | break; |
|
| 545 | 554 | case XK_Right: |
|
| 546 | 555 | case XK_Down: |
|
| 547 | - | if(cursor < len) |
|
| 548 | - | cursor++; |
|
| 549 | - | else if(sel && sel->right) { |
|
| 556 | + | if(cursor < len) { |
|
| 557 | + | do { |
|
| 558 | + | cursor++; |
|
| 559 | + | } while(cursor < len && !IS_UTF8_1ST_CHAR(text[cursor])); |
|
| 560 | + | } else if(sel && sel->right) { |
|
| 550 | 561 | sel=sel->right; |
|
| 551 | 562 | if(sel == next) { |
|
| 552 | 563 | curr = next; |
|