rem: if (!tPtr->selection.count) { tPtr->selection.position = tPtr->cursorPosition; }  tPtr->cursorPosition = pointToCursorPosition(tPtr, event->xmotion.x);  tPtr->selection.count = tPtr->cursorPosition - tPtr->selection.position;    paintCursor(tPtr); paintTextField(tPtr);  }
add: }
context: handleTextFieldActionEvents(XEvent *event, void *data){    TextField *tPtr = (TextField*)data;    static int move;        CHECK_CLASS(data, WC_TextField);    switch (event->type) {     case KeyPress:        if (tPtr->flags.enabled && tPtr->flags.focused)            handleTextFieldKeyPress(tPtr, event);	        break;     case MotionNotify:        if (tPtr->flags.enabled && (event->xmotion.state & Button1Mask)) {        if (tPtr->viewPosition < tPtr->textLen && event->xmotion.x >                tPtr->usableWidth) {            if (WMWidthOfString(tPtr->font,                    &(tPtr->text[tPtr->viewPosition]),                    tPtr->cursorPosition-tPtr->viewPosition)                    > tPtr->usableWidth) {                tPtr->viewPosition++;            }        }    	else if (tPtr->viewPosition > 0 && event->xmotion.x < 0) {            paintCursor(tPtr);            tPtr->viewPosition--;        }        if (!tPtr->selection.count) {            tPtr->selection.position = tPtr->cursorPosition;        }        tPtr->cursorPosition = pointToCursorPosition(tPtr, event->xmotion.x);        tPtr->selection.count = tPtr->cursorPosition - tPtr->selection.position;        /*        printf("notify %d %d\n",event->xmotion.x,tPtr->usableWidth);        */        paintCursor(tPtr);        paintTextField(tPtr);	    }        if (move) {        int count;        XSetSelectionOwner(tPtr->view->screen->display,                XA_PRIMARY, None, CurrentTime);        count = tPtr->selection.count < 0            ? tPtr->selection.position + tPtr->selection.count             : tPtr->selection.position;        XStoreBuffer(tPtr->view->screen->display,                        &tPtr->text[count] , abs(tPtr->selection.count), 0);        }	break;     case ButtonPress:        move = 1;        switch (tPtr->flags.alignment) {            int textWidth;         case WARight:            textWidth = WMWidthOfString(tPtr->font, tPtr->text, tPtr->textLen);            if (tPtr->flags.enabled && !tPtr->flags.focused) {                WMSetFocusToWidget(tPtr);            } else if (tPtr->flags.focused) {                tPtr->selection.count = 0;            }            if(textWidth < tPtr->usableWidth){                tPtr->cursorPosition = pointToCursorPosition(tPtr,                                      event->xbutton.x - tPtr->usableWidth                                     + textWidth);            }            else tPtr->cursorPosition = pointToCursorPosition(tPtr,                                      event->xbutton.x);            /*            tPtr->cursorPosition = pointToCursorPosition(tPtr,                                      event->xbutton.x);                tPtr->cursorPosition += tPtr->usableWidth - textWidth;            }            tPtr->cursorPosition = pointToCursorPosition(tPtr,                                      event->xbutton.x);                                     */            paintTextField(tPtr);            break;                 case WALeft:            if (tPtr->flags.enabled && !tPtr->flags.focused) {                WMSetFocusToWidget(tPtr);                tPtr->cursorPosition = pointToCursorPosition(tPtr,                                      event->xbutton.x);                paintTextField(tPtr);            } else if (tPtr->flags.focused) {                tPtr->cursorPosition = pointToCursorPosition(tPtr,                                      event->xbutton.x);                tPtr->selection.count = 0;                paintTextField(tPtr);            }            if (event->xbutton.button == Button2 && tPtr->flags.enabled) {                char *text;                text = W_GetTextSelection(tPtr->view->screen,                              tPtr->view->screen->clipboardAtom);                if (!text) {                text = W_GetTextSelection(tPtr->view->screen, XA_CUT_BUFFER0);                }                if (text) {                WMInsertTextFieldText(tPtr, text, tPtr->cursorPosition);                XFree(text);                WMPostNotificationName(WMTextDidChangeNotification, tPtr, NULL);                }            }            break;        }	break;     case ButtonRelease:        move = 0;        break;    }}