rem: } else { paintCursor(tPtr); } }
add: } else paintCursor(tPtr); } if (event->xkey.state & ShiftMask) cancelSelection = 0;
context: handleTextFieldKeyPress(TextField *tPtr, XEvent *event){    char buffer[64];    KeySym ksym;    int count, refresh = 0;    int control_pressed = 0;    if (((XKeyEvent *) event)->state & WM_EMACSKEYMASK) {	control_pressed = 1;    }    count = XLookupString(&event->xkey, buffer, 63, &ksym, NULL);    buffer[count] = '\0';    if (!(event->xkey.state & ShiftMask)) {        if (tPtr->selection.count)            refresh = 1;        tPtr->prevselection = tPtr->selection;        tPtr->selection.position = tPtr->cursorPosition;        tPtr->selection.count = 0;    }    /* Be careful in any case in this switch statement, never to call     * to more than a function that can generate text change notifications.     * Only one text change notification should be sent in any case.     * Else hazardous things can happen.     * Maybe we need a better solution than the function wrapper to inform     * functions that change text in text fields, if they need to send a     * change notification or not. -Dan     */    switch (ksym) {     case XK_Tab:#ifdef XK_ISO_Left_Tab     case XK_ISO_Left_Tab:#endif	if (event->xkey.state & ShiftMask) {	    if (tPtr->view->prevFocusChain) {		W_SetFocusOfTopLevel(W_TopLevelOfView(tPtr->view),				     tPtr->view->prevFocusChain);		tPtr->flags.notIllegalMovement = 1;	    }	    NOTIFY(tPtr, didEndEditing, WMTextDidEndEditingNotification,		   (void*)WMBacktabTextMovement);	} else {	    if (tPtr->view->nextFocusChain) {		W_SetFocusOfTopLevel(W_TopLevelOfView(tPtr->view),				     tPtr->view->nextFocusChain);		tPtr->flags.notIllegalMovement = 1;	    }	    NOTIFY(tPtr, didEndEditing, WMTextDidEndEditingNotification,		   (void*)WMTabTextMovement);	}	break;     case XK_Return:	NOTIFY(tPtr, didEndEditing, WMTextDidEndEditingNotification,	       (void*)WMReturnTextMovement);	break;     case WM_EMACSKEY_LEFT:	if (!control_pressed) {	    goto normal_key;	}#ifdef XK_KP_Left     case XK_KP_Left:#endif     case XK_Left:	if (tPtr->cursorPosition > 0) {	    paintCursor(tPtr);            if (event->xkey.state & ControlMask) {                int i;                for (i = tPtr->cursorPosition - 1; i >= 0; i--)                    if (tPtr->text[i] == ' ' || i == 0) {                        tPtr->cursorPosition = i;                        break;                    }            } else {		tPtr->cursorPosition--;            }	    if (tPtr->cursorPosition < tPtr->viewPosition) {		tPtr->viewPosition = tPtr->cursorPosition;		refresh = 1;	    } else {		paintCursor(tPtr);	    }	}	break;    case WM_EMACSKEY_RIGHT:      if (!control_pressed) {	goto normal_key;      }#ifdef XK_KP_Right    case XK_KP_Right:#endif     case XK_Right:	if (tPtr->cursorPosition < tPtr->textLen) {	    paintCursor(tPtr);            if (event->xkey.state & ControlMask) {                int i;                for (i = tPtr->cursorPosition + 1; i <= tPtr->textLen; i++)                    if (tPtr->text[i] == ' ' || i == tPtr->textLen) {                        tPtr->cursorPosition = i;                        break;                    }            } else {               tPtr->cursorPosition++;            }	    while (WMWidthOfString(tPtr->font,				&(tPtr->text[tPtr->viewPosition]),				tPtr->cursorPosition-tPtr->viewPosition)		   > tPtr->usableWidth) {		tPtr->viewPosition++;		refresh = 1;	    }	    if (!refresh)		paintCursor(tPtr);	}	break;	    case WM_EMACSKEY_HOME:      if (!control_pressed) {	goto normal_key;      }#ifdef XK_KP_Home    case XK_KP_Home:#endif     case XK_Home:	if (tPtr->cursorPosition > 0) {	    paintCursor(tPtr);	    tPtr->cursorPosition = 0;	    if (tPtr->viewPosition > 0) {		tPtr->viewPosition = 0;		refresh = 1;	    } else {		paintCursor(tPtr);	    }	}	break;	    case WM_EMACSKEY_END:      if (!control_pressed) {	goto normal_key;      }#ifdef XK_KP_End     case XK_KP_End:#endif     case XK_End:	if (tPtr->cursorPosition < tPtr->textLen) {	    paintCursor(tPtr);	    tPtr->cursorPosition = tPtr->textLen;	    tPtr->viewPosition = 0;	    while (WMWidthOfString(tPtr->font,				   &(tPtr->text[tPtr->viewPosition]),				   tPtr->textLen-tPtr->viewPosition)		   > tPtr->usableWidth) {		tPtr->viewPosition++;		refresh = 1;	    }	    if (!refresh)		paintCursor(tPtr);	}	break;	     case WM_EMACSKEY_BS:      if (!control_pressed) {	goto normal_key;      }     case XK_BackSpace:	if (tPtr->cursorPosition > 0) {            WMRange range;            if (tPtr->prevselection.count) {                range.position = tPtr->prevselection.count < 0 		    ? tPtr->prevselection.position + tPtr->prevselection.count 		    : tPtr->prevselection.position;		range.count = abs(tPtr->prevselection.count);	    } else {                range.position = tPtr->cursorPosition - 1;                range.count = 1;            }	    WMDeleteTextFieldRange(tPtr, range);            NOTIFY(tPtr, didChange, WMTextDidChangeNotification,                   (void*)WMDeleteTextEvent);	}	break;	    case WM_EMACSKEY_DEL:      if (!control_pressed) {	goto normal_key;      }#ifdef XK_KP_Delete    case XK_KP_Delete:#endif     case XK_Delete:	if (tPtr->cursorPosition < tPtr->textLen || tPtr->prevselection.count) {            WMRange range;            if (tPtr->prevselection.count) {                range.position = tPtr->prevselection.count < 0 		    ? tPtr->prevselection.position + tPtr->prevselection.count		    : tPtr->prevselection.position;                range.count = abs(tPtr->prevselection.count);            } else {		range.position = tPtr->cursorPosition;		range.count = 1;            }	    WMDeleteTextFieldRange(tPtr, range);            NOTIFY(tPtr, didChange, WMTextDidChangeNotification,                   (void*)WMDeleteTextEvent);	}	break;    normal_key:     default:	if (count > 0 && !iscntrl(buffer[0])) {	    WMRange range;	    if (tPtr->prevselection.count) {                range.position = tPtr->prevselection.count < 0 		    ? tPtr->prevselection.position + tPtr->prevselection.count		    : tPtr->prevselection.position;                range.count = abs(tPtr->prevselection.count);            } else {		range.position = tPtr->cursorPosition;		range.count = 1;            }            if (tPtr->prevselection.count)                WMDeleteTextFieldRange(tPtr, range);	    WMInsertTextFieldText(tPtr, buffer, tPtr->cursorPosition);            NOTIFY(tPtr, didChange, WMTextDidChangeNotification,                   (void*)WMInsertTextEvent);	} else {	    return;	}	break;    }    if (event->xkey.state & ShiftMask) {        if (tPtr->selection.count == 0)            tPtr->selection.position = tPtr->cursorPosition;        tPtr->selection.count = tPtr->cursorPosition - tPtr->selection.position;        refresh = 1;    }    tPtr->prevselection.count = 0;    if (refresh) {	paintTextField(tPtr);    }}