Re: NSTextView and changing the selected text's color
Re: NSTextView and changing the selected text's color
- Subject: Re: NSTextView and changing the selected text's color
- From: Ross Carter <email@hidden>
- Date: Fri, 30 May 2008 11:15:20 -0400
Instead of NSTextView setMarkedTextAttributes:, I think you want to
look at setSelectedTextAttributes:. "Marked text" refers to text input
that is not final. When you type option-e, NSTextView displays an
accent glyph with a yellow background. That's marked text. When you
type a letter, the the glyph is completed and the yellow marking goes
away.
Ross
On May 30, 2008, at 7:25 AM, Mattias Arrelid wrote:
Hi everyone,
We have a subclass of NSTextView (SPTextView). A couple of these have
some text with [NSColor grayColor] set as the
NSForegroundColorAttributeName. It looks good, but when the user
starts selecting text things go bad™. Since grey on light blue (the
default system selection color) isn't very readable one could argue
that we should change the selection color. That is pretty straight
forward, but we'd rather not mess with this since the user might have
her own highlight color set (through System Preferences / Appearance).
The next approach would be to use NSTextView's
setMarkedTextAttributes:. It takes a dictionary as paramater, with the
following restrictions (according to the documentation): "A dictionary
of attributes used to draw marked text. Text color, background color,
and underline are the only supported attributes for marked text.".
Regardless of how I try to specify these (I assume the attributes that
are valid are NSForegroundColorAttributeName,
NSBackgroundColorAttributeName, NSUnderlineColorAttributeName and
NSUnderlineStyleAttributeName), that call doesn't affect the view.
As a last resort, we could implement
setSelectedRange:affinity:stillSelecting: in our NSTextView subclass,
and set the foreground color of the selected range... but that would
mean that we would have to change it back to whatever color it had
before the selection took place. That doesn't feel right.
Reading http://developer.apple.com/documentation/Cocoa/Conceptual/TextEditing/Tasks/SetFocus.html
indicates that setMarkedTextAttributes: should do just this, but I
cannot seem to get it working.
Any suggestions?
Best regards
Mattias
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden