Finding the span of a paragraph[permalink]The NSString paragraphRangeForRange: method gives you the span of a paragraph. If you're using the text architecture, you need to get the string from the text storage. This chunklet shows the paragraph span for the current selection:

I've heard that scrollRangeToVisible is O(N) for the length of the text. So be on the lookout if you have lots of text involved.

Show NSTextField text in gray if the field is disabled[permalink]NSTextField doesn't change its text color if the field is enabled or disabled (?) Even more bizarre, using NSColor's disabledControlTextColor won't draw the text in the disabled color. You need to use the secondarySelectedControlColor, which supposedly is for active controls that don't have focus. Go figure.

To do it yourself, subclass NSTextField and override setEnabled: to change the color:

This actually kind of a gross workaround for a Cocoa bug - the disabled color is getting made darker rather than lighter. The secondarySelectedControlColor ends up looking disabled by a happy coincidence that it starts out lighter before being darkened. (or something like this. UberDude Dave MacLachlan has done the legwork to figure out the underlying problem.)

Truncating text in the middle of a string[permalink]Sometimes you see text that is of the form "Some Gro...eral Fish", with the middle truncated but the ends still readable. You can get this effect yourself with: