With a dark color scheme in Xcode 4 the i-beam cursor (aka text selection cursor) is nearly invisible. Is there a way to change the color of this cursor, either for Xcode speci
Unfortunately this is a difference between Carbon and Cocoa cursors—Cocoa cursors won't invert; at least, up to Snow Leopard. In Lion, even Carbon cursors behave like you don't want.
If you've got a machine running Snow Leopard or earlier, compare the I-beam behavior in BBEdit or TextWrangler (which use Carbon cursors), for example; it'll become entirely white on a black background. Even this is a bit fragile—when I change the screen magnification, BBEdit's formerly-white cursor becomes black.
You can still set a Carbon cursor in your Cocoa app. Try this in a NSTextView subclass:
#import
[...]
- (void)resetCursorRects;
{
// disable existing cursor setting behavior
}
- (void)cursorUpdate:(NSEvent *)event;
{
SetThemeCursor(kThemeIBeamCursor);
}
- (void)updateTrackingAreas;
{
for (NSTrackingArea *trackingArea in [self trackingAreas])
[self removeTrackingArea:trackingArea];
NSTrackingArea *trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect options:NSTrackingCursorUpdate | NSTrackingActiveInKeyWindow | NSTrackingInVisibleRect owner:self userInfo:nil];
[self addTrackingArea:trackingArea];
}
(In 64-bit you'll see that this function is excluded from the headers, but the symbol is there and works.) If you're sufficiently motivated, you could potentially patch Xcode to do some variant of the above, perhaps from an Xcode plugin.
If you're on Lion, here's what it is supposed to look like:
So I'd suggest filing a bug with Apple to make the systemwide I-beam cursor (or NSCursor in general) properly handle dark backgrounds; it's not an Xcode-specific issue and it should really have been fixed years ago.