PDA

View Full Version : [Resolved] NSTextInputClient




MrFusion
Jun 10, 2011, 04:32 PM
I have a subclass of NSResponder that implements the NSTextInputClient protocol.

One of the required functions is this one:

- (void)insertText:(id)aString replacementRange:(NSRange)replacementRange


In whatever user input I give, I never seem to get a valid replacementRange.

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!



chown33
Jun 10, 2011, 05:37 PM
Post some actual output from the NSLog.

1. Describe what you expected to happen.
2. Describe what actually happened.

MrFusion
Jun 11, 2011, 03:18 AM
Post some actual output from the NSLog.

1. Describe what you expected to happen.
2. Describe what actually happened.

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.

chown33
Jun 11, 2011, 11:10 AM
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.

NSTextInputClient protocol reference:
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/NSTextInputClient_Protocol/Reference/Reference.html%23//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.