catlan
catlan

Reputation: 25246

Strange behaviour of NSTextField with NSAttributedString with text selection

I’m seeing some strange behaviour where a NSTextField with an attributed string loses its attributes (for example some text was bold and is no longer bold) when selectable is set and some text is selected.

Setting allowsEditingTextAttributes to YES seems to keep the bold attribute, but changes color (white to black).

Is there an easy workaround?

Upvotes: 0

Views: 484

Answers (1)

catlan
catlan

Reputation: 25246

BOOL allowsEditingTextAttributes

Discussion
If YES, and the text value is an attributed string, it is displayed using the attributed string’s visual settings, which can be modified in the font panel.; if flag is NO and the text is an attributed string. the string attributes (font, color, etc.) are ignored and the string is displayed based on the text field’s settings. Setting the attributed string’s attributes are ignored when displaying the string and when the text field is editing.

Text selections in an NSTextField are handled by the field editor. Unfortunately the field editor does not take into account text field’s font and color settings.

For this to work the attribute string needs to include the text field’s font and color settings.

Upvotes: 1

Related Questions