src/video/uikit/SDL_uikitview.m
branchiOS-improvements
changeset 9525 64e3f446d6d7
parent 9524 9de159f9cefd
child 9527 bbd9326ecacf
     1.1 --- a/src/video/uikit/SDL_uikitview.m	Thu Nov 20 18:45:04 2014 -0400
     1.2 +++ b/src/video/uikit/SDL_uikitview.m	Fri Nov 21 03:29:57 2014 -0400
     1.3 @@ -193,19 +193,17 @@
     1.4  /* UITextFieldDelegate method.  Invoked when user types something. */
     1.5  - (BOOL)textField:(UITextField *)_textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
     1.6  {
     1.7 -    if ([string length] == 0) {
     1.8 +    NSUInteger len = string.length;
     1.9 +
    1.10 +    if (len == 0) {
    1.11          /* it wants to replace text with nothing, ie a delete */
    1.12          SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_BACKSPACE);
    1.13          SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_BACKSPACE);
    1.14 -    }
    1.15 -    else {
    1.16 +    } else {
    1.17          /* go through all the characters in the string we've been sent
    1.18             and convert them to key presses */
    1.19 -        int i;
    1.20 -        for (i = 0; i < [string length]; i++) {
    1.21 -
    1.22 +        for (int i = 0; i < len; i++) {
    1.23              unichar c = [string characterAtIndex:i];
    1.24 -
    1.25              Uint16 mod = 0;
    1.26              SDL_Scancode code;
    1.27  
    1.28 @@ -224,16 +222,20 @@
    1.29                  /* If character uses shift, press shift down */
    1.30                  SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LSHIFT);
    1.31              }
    1.32 +
    1.33              /* send a keydown and keyup even for the character */
    1.34              SDL_SendKeyboardKey(SDL_PRESSED, code);
    1.35              SDL_SendKeyboardKey(SDL_RELEASED, code);
    1.36 +
    1.37              if (mod & KMOD_SHIFT) {
    1.38                  /* If character uses shift, press shift back up */
    1.39                  SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LSHIFT);
    1.40              }
    1.41          }
    1.42 +
    1.43          SDL_SendKeyboardText([string UTF8String]);
    1.44      }
    1.45 +
    1.46      return NO; /* don't allow the edit! (keep placeholder text there) */
    1.47  }
    1.48