I need to trap-and-replace various keypresses in the field editor. I do this with -controlTextDidChange: in my delegate. So, when the user presses ">", I replace it with a "superset of" (⊃) character (in case this does not come out on the list, I'm going to represent the "superset of" character with *s*). Here is the code:

-(void)controlTextDidChange:(NSNotification *)aNotification
{
        // Set fieldString to the string showing in the field editor
NSMutableString *fieldString = [NSMutableString stringWithString: [fieldEd string]];

        // Change ">" to horseshoe in fieldString
        [fieldString replaceOccurrencesOfString:@">"
        withString:[NSString stringWithFormat:@"%C",0x2283] // 0x2283 is *s*
        options:NSLiteralSearch
        range:NSMakeRange(0,[fieldString length])];

NSRange selectedRange = [fieldEd selectedRange]; // Where the cursor is before the changes [fieldEd setString:fieldString]; // Set field editor to new string. Cursor will be set to the end of the string [fieldEd setSelectedRange:selectedRange]; // Return cursor to where it should be
}

Now, this always makes the change. The problem is that in certain circumstances, the font height of some characters in the string, not related to the search-and-replace function, is changed. But only sometimes. For example, if I enter:

C>C ... this becomes C*ss*C just as it should.

But if I enter:

>C> ... this becomes *ss*C*ss* as it should, except the C is a half- height C. Everything else looks normal.

I also make other search-and-replaces in the -controlTextDidChange method (I've given only the basic snippet of code), some of which exhibit this problem, and others of which do not. It seems to depend on the replacement string.

Some additional background:

(1) I have "no rich text" checked for the relevant text fields in IB.
(2) If I copy-and-paste from the field editor into TextEdit, everything looks normal in all cases. (3) When the user presses return and the text is passed to the text field, everything looks normal in all cases.

I'm not sure why it is doing this; but more importantly, I'm not sure how to fix it. Any help would be greatly appreciated._______________________________________________

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

Reply via email to