user142019
user142019

Reputation:

Drawing multiple cursors in an NSTextView

Not about UITextView!

In a Mac application I want to draw multiple cursors in an NSTextView (in an NSScrollView). One cursor is of course the position where you are typing, the one you see when you type normally.

The other cursors are the positions where other people on the same are typing. The positions of these cursors are NSNumbers in an NSArray.

How can I override NSTextView's draw method to draw a cursor at a specific character position? A pipe character is not an option.


Oh, note that the font of all text in the NSTextView is always Monaco 10pt.

Upvotes: 3

Views: 910

Answers (1)

NSResponder
NSResponder

Reputation: 16861

- (void)drawRect:(NSRect)dirtyRect
{
[super drawRect:dirtyRect];

// draw your cursors here.

}

You can get a cursor image from the NSCursor class, and you can figure out where to draw it from your view's NSLayoutManager instance. I would highly recommend that you come up with some visual differentiation between the usual insertion point indicator, and those denoting other users' insertion points.

Upvotes: 1

Related Questions