Resolved NSTextInputClient

Discussion in 'Mac Programming' started by MrFusion, Jun 10, 2011.

  1. MrFusion, Jun 10, 2011
    Last edited: Jun 11, 2011

    macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #1
    I have a subclass of NSResponder that implements the NSTextInputClient protocol.

    One of the required functions is this one:
    Code:
    - (void)insertText:(id)aString replacementRange:(NSRange)replacementRange
    
    In whatever user input I give, I never seem to get a valid replacementRange.
    Code:
    NSLog(@"%@",NSStringFromRange(replacementRange));
    
    Does anyone know under which circumstances a valid range is supposed to be given?
    My code works since I just use the selectedRange (also a required function), but I want to make sure I don't miss anything here.

    The "TextInputView" sample code implements this function as well, but overrides the replacementRange (in most cases?).

    Your insight into this function is appreciated!
     
  2. macrumors 603

    Joined:
    Aug 9, 2009
    #2
    Post some actual output from the NSLog.

    1. Describe what you expected to happen.
    2. Describe what actually happened.
     
  3. thread starter macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #3
    I type in any letter -> I get {9223372036854775807, 0} -> I expect something like {4,0} (no selection) or {4,6} (with text selected). (0,4 and 6 are random examples.)
    Likewise, TextInputView gets a {very large number,0} as input.
     
  4. macrumors 603

    Joined:
    Aug 9, 2009
    #4
    NSTextInputClient protocol reference:
    http://developer.apple.com/library/...e.html#//apple_ref/occ/intf/NSTextInputClient

    Find the selectedRange method and read what it says is the range when there's no selection. Then look up what NSNotFound is. Maybe even print it out in your code.
     

Share This Page