Distinguish Pending Text from Committed Text

2009-05-19 Thread Dong Feng
When using an non-English input method, such as Japanese or Chinese,
the entered characters are first in a pending status (i.e. with an
underscore). Pressing the space key make those pending text converted
to the actual non-English characters. Pressing the Enter key make the
underscore beneath the letters disappear. Either way, the pending text
become committed.

I want to programmatically distinguish the committed text from the
pending one, in a NSTextField. [NSTextField stringValue] returns the
sum, not only the committed part. Is there any way to do so?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Distinguish Pending Text from Committed Text

2009-05-19 Thread Michael Ash
On Tue, May 19, 2009 at 9:48 AM, Dong Feng middle.fengd...@gmail.com wrote:
 When using an non-English input method, such as Japanese or Chinese,
 the entered characters are first in a pending status (i.e. with an
 underscore). Pressing the space key make those pending text converted
 to the actual non-English characters. Pressing the Enter key make the
 underscore beneath the letters disappear. Either way, the pending text
 become committed.

 I want to programmatically distinguish the committed text from the
 pending one, in a NSTextField. [NSTextField stringValue] returns the
 sum, not only the committed part. Is there any way to do so?

Check out the NSTextInput protocol. NSTextView conforms to that
protocol, so if you get the field editor from your NSTextField, you
can use those methods. I believe that marked is what that protocol
calls what you are referring to as pending, but I'm not 100% sure.

(Warning: I've never tried any of this.)

Mike
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Distinguish Pending Text from Committed Text

2009-05-19 Thread Gideon King
You can use the markedRange method and then remove it from the text  
range you are dealing with to get only the committed text.


Gideon


On Tue, May 19, 2009 at 9:48 AM, Dong Feng middle.fengd...@gmail.com  
wrote:

When using an non-English input method, such as Japanese or Chinese,
the entered characters are first in a pending status (i.e. with an
underscore). Pressing the space key make those pending text converted
to the actual non-English characters. Pressing the Enter key make the
underscore beneath the letters disappear. Either way, the pending text
become committed.

I want to programmatically distinguish the committed text from the
pending one, in a NSTextField. [NSTextField stringValue] returns the
sum, not only the committed part. Is there any way to do so?



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Distinguish Pending Text from Committed Text

2009-05-19 Thread Dong Feng
Thanks Michael and Gideon's reply. [NSTextInput markedRange] works.

A minor question is that [NSWindow fieldEditor] returns an NSText*,
rather than an NSTextView*. I think that's because of historical
reason and it should be safe to always cast a returned NSText point to
an NSTextView. Is it safe?



2009/5/20 Michael Ash michael@gmail.com:
 On Tue, May 19, 2009 at 9:48 AM, Dong Feng middle.fengd...@gmail.com wrote:
 When using an non-English input method, such as Japanese or Chinese,
 the entered characters are first in a pending status (i.e. with an
 underscore). Pressing the space key make those pending text converted
 to the actual non-English characters. Pressing the Enter key make the
 underscore beneath the letters disappear. Either way, the pending text
 become committed.

 I want to programmatically distinguish the committed text from the
 pending one, in a NSTextField. [NSTextField stringValue] returns the
 sum, not only the committed part. Is there any way to do so?

 Check out the NSTextInput protocol. NSTextView conforms to that
 protocol, so if you get the field editor from your NSTextField, you
 can use those methods. I believe that marked is what that protocol
 calls what you are referring to as pending, but I'm not 100% sure.

 (Warning: I've never tried any of this.)

 Mike
 ___

 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

 Please do not post admin requests or moderator comments to the list.
 Contact the moderators at cocoa-dev-admins(at)lists.apple.com

 Help/Unsubscribe/Update your Subscription:
 http://lists.apple.com/mailman/options/cocoa-dev/middle.fengdong%40gmail.com

 This email sent to middle.fengd...@gmail.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Distinguish Pending Text from Committed Text

2009-05-19 Thread Gwynne Raskind

On May 19, 2009, at 10:35 PM, Dong Feng wrote:

Thanks Michael and Gideon's reply. [NSTextInput markedRange] works.

A minor question is that [NSWindow fieldEditor] returns an NSText*,
rather than an NSTextView*. I think that's because of historical
reason and it should be safe to always cast a returned NSText point to
an NSTextView. Is it safe?


I don't know if it's safe 100% of the time, but if you do it, drop an  
assert in your code for sanity's sake:


NSAssert( [returnedFieldEditor isKindOfClass:[NSTextView class]] ==  
YES, @Field editor is, in fact, an NSTextView. );


-- Gwynne, Daughter of the Code
This whole world is an asylum for the incurable.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com