rem: case XK_Right: case XK_Left: if(tPtr->currentChunk) { short w; Chunk *chunk = tPtr->currentChunk; if(chunk->type == ctText) { WMFont *font = (tPtr->monoFont)?tPtr->dFont:chunk->font; if(ksym==XK_Right) { short pos = (tPtr->tpos<chunk->chars)?tPtr->tpos+1: chunk->chars; w = WMWidthOfString(font,&chunk->text[pos],1); } else { short pos = (tPtr->tpos>0)?tPtr->tpos-1:0; w = WMWidthOfString(font,&chunk->text[pos],1); } } else { w = chunk->pixmap->width; } if(ksym==XK_Right) w = -w; cursorToTextPosition(tPtr, tPtr->clicked.x-w, tPtr->clicked.y); } else { if(ksym==XK_Right) ksym = XK_Down; else ksym = XK_Up; goto noCChunk; } break;
add: case XK_Right: case XK_Left: if (tPtr->currentChunk) { short w; Chunk *chunk = tPtr->currentChunk;
context: handleTextKeyPress(Text *tPtr, XEvent *event){    char buffer[2];    KeySym ksym;    int control_pressed = False;    if(!tPtr->editable) return;    if (((XKeyEvent *) event)->state & WM_EMACSKEYMASK)        control_pressed = True;    buffer[XLookupString(&event->xkey, buffer, 1, &ksym, NULL)] = '\0';    switch(ksym) {    case XK_Right:    case XK_Left:        if(tPtr->currentChunk) {            short w;            Chunk *chunk = tPtr->currentChunk;            if(chunk->type == ctText) {                WMFont *font = (tPtr->monoFont)?tPtr->dFont:chunk->font;                if(ksym==XK_Right) {                    short pos = (tPtr->tpos<chunk->chars)?tPtr->tpos+1:                        chunk->chars;                    w = WMWidthOfString(font,&chunk->text[pos],1);                } else {                    short pos = (tPtr->tpos>0)?tPtr->tpos-1:0;                    w = WMWidthOfString(font,&chunk->text[pos],1);                }            } else { w = chunk->pixmap->width; }            if(ksym==XK_Right) w = -w;            cursorToTextPosition(tPtr, tPtr->clicked.x-w, tPtr->clicked.y);        } else {            if(ksym==XK_Right) ksym = XK_Down;            else ksym = XK_Up;            goto noCChunk;        }        break;    case XK_Down:    case XK_Up:    noCChunk: { short h = tPtr->clheight-2;        if(ksym==XK_Down) h = -h;    cursorToTextPosition(tPtr, tPtr->clicked.x, tPtr->clicked.y-h);    } break;    case XK_BackSpace:        deleteTextInteractively(tPtr, dtBackSpace);        break;    case XK_Delete:    case XK_KP_Delete:        deleteTextInteractively(tPtr, dtDelete);        break;    case XK_Return:        buffer[0] = '\n';    default:        if(buffer[0] != '\0' && (buffer[0] == '\n' || !iscntrl(buffer[0])))            insertTextInteractively(tPtr, buffer);        else if(control_pressed && ksym==XK_r)        {Bool i = !tPtr->rulerShown; WMShowTextRuler(tPtr, i);            tPtr->rulerShown = i; }    }}