On May 5, 2009, at 9:42 AM, Mic Pringle wrote:

I'm working on a project that accepts user input via an NSTextView
instance, but I would like to have a user-defined number of spaces
inserted when the tab key is pressed. Similar to how TextMate allows.

What is the best way to acheive this ? NSLayoutManager or key press events ?

Any help will be greatly appreciated.

One way to accomplish this would be to implement this method on your NSTextView delegate (typed in Mail, YMMV):

- (BOOL)control:(NSControl*)control textView:(NSTextView*)textView doCommandBySelector:(SEL)commandSelector
{
    if (commandSelector == @selector(insertTab:)) {
        [textView insertText:spacesForTabsString];
        return YES;
    }

    return NO;
}


Ashley
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to