Re: NSTextInput problems
Re: NSTextInput problems
- Subject: Re: NSTextInput problems
- From: Aki Inoue <email@hidden>
- Date: Mon, 27 May 2002 17:01:45 -0700
Eyal,
1. How does the "Marked Text" relate to the selection? I saw no way of
reporting where my selection is and it seems that the caller thinks
that the insertion is always at index 1. I suspect that I'm not
intializing or updating something.
Conceptually the marked text is a temporary editing "hole" inside your
document that's owned by the input manager. And, from the document
point of view, the marked text itself is a special selection. So, both
the -insertText: and -setMarkedText:selectedRange: methods are expected
to replace the whole marked text with successive invocations of the
methods with their arguments.
Now, the selected range argument in the -setMarkedText:selectedRange:
method is the selection inside the marked text. Since the content of
the marked range is basically owned by the input manager, the cursor
movement including the selection is the input manager's responsibility.
The index in the argument is, thus, relative to the beginning of the
marked range, not from the document beginning. I assume you've been
testing your code with dead keys for Roman accented characters. In that
case, the length of the marked range is almost always 1, and, the cursor
position is always at the index 1. With more complex languages like
Japanese, Chinese, or Korean, the marked text can be a whole sentence.
In that case, the selected range can move inside the marked text.
2. The docs say that hasMarkedText is not called from the input
manager, but in my app it is being called(?) (caller is NSInputContext)
Should I base my answer on whether the range is empty or not or should
I just say "YES" if I support the concept?
The answer is the former. The conformance to the NSTextInput protocol
itself is sufficient to declare support of the concept.
3. insertText. What should I do to the marked text range?
Both the -insertText: and -setMarkedText:selectedRange: methods are
expected to replace the previous marked text with the new argument. In
the case of insertText:, you can clear the marked text range information
cached in your document.
Since my view is not based or connected with the regular text system I
must implement this but the documentation is a bit weak on this...
The good news is, there is a concept chapter for the Cocoa text input
system in the developer documentation is being worked on. Stay tuned...
Aki
On 2002.05.27, at 16:26, Eyal Redler wrote:
Hi All,
I'm having trouble with NSTextInput protocol.
I've scanned every resource for answers on this. I hope someone here
can help me.
I have a custom view I want to allow text input in. I cannot get
accented characters with keyDown+insertText.
Since my view is not based or connected with the regular text system I
must implement this but the documentation is a bit weak on this...
Questions:
1. How does the "Marked Text" relate to the selection? I saw no way of
reporting where my selection is and it seems that the caller thinks
that the insertion is always at index 1. I suspect that I'm not
intializing or updating something.
2. The docs say that hasMarkedText is not called from the input
manager, but in my app it is being called(?) (caller is NSInputContext)
Should I base my answer on whether the range is empty or not or should
I just say "YES" if I support the concept?
3. insertText. What should I do to the marked text range?
My implementation goes something like this:
- (NSAttributedString *)
attributedSubstringFromRange:(NSRange)theRange {
return [textModel attributedSubstringFromRange:theRange];
}
- (unsigned int)characterIndexForPoint:(NSPoint)thePoint {
return -1;// To do
}
- (long) conversationIdentifier{
return (long)textModel;
}
- (NSRect) firstRectForCharacterRange:(NSRange)theRange {
NSRect aRect; // to do
return aRect;
}
- (BOOL) hasMarkedText {
if (_inputManagerRange.length>0)
return YES;
else
return NO;
}
- (void)insertText:(NSString *)aString {
[textModel userEnteredText:aString];
}
- (NSRange) markedRange {
if ([self hasMarkedText])
return _inputManagerRange;
else
return NSMakeRange(NSNotFound,0);
}
- (NSRange) selectedRange {
return [textModel getSelectedRange];
}
- (void) setMarkedText:(id)aString selectedRange:(NSRange)selRange {
[textModel replaceTextInRange:aString range:selRange];
_inputManagerRange=selRange;
}
- (void) unmarkText {
_inputManagerRange.location=NSNotFound;
_inputManagerRange.length=0;
}
- (NSArray*) validAttributesForMarkedText {
return [NSArray array];
}
I'm really stuck on this...
Thanks,
Eyal
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.