8

I'm setting the textContainerInset of an NSTextView to some values.

self.textView.textContainerInset = NSMakeSize(10, 10);

How do you make the text view selectable in the inset area? The text cursor appears but nothing happens if I try to select the text area within this inset.

Here is additional sample code you can add to a blank Cocoa Application project to see this behavior.

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    NSTextView *textView = [[NSTextView alloc] initWithFrame:self.window.contentView.bounds];
    textView.string = @"1\n2\n3\n4\n5";
    textView.textContainerInset = NSMakeSize(10, 10);
    [self.window.contentView addSubview:textView];
}
Berry Blue
  • 15,330
  • 18
  • 62
  • 113
  • What are the properties of the textView itself, is it enabled for editing? – trumpetlicks Nov 05 '15 at 01:24
  • Yes it's enabled for editing. If I comment out all other set properties it still exhibits the same behavior. – Berry Blue Nov 05 '15 at 02:03
  • How large is the textView? The reason I am asking is I have quite a few small textViews that an offset of 10 in BOTH the X and Y directions could very possibly make it seem as if it is outside the VIEWABLE area. – trumpetlicks Nov 06 '15 at 17:18
  • It's a large text view. The cursor has to be touching the letter before it selects the text view but the cursor changes to the text cursor when it's within the text container insets. – Berry Blue Nov 06 '15 at 20:43

1 Answers1

0

Seems like NSTextView believes in its insets so much that it returns nil from hitTest for the events on the inset area.

What helped me is to override hitTest and return self for these cases, then TextView will process such events correctly.

A bit risky solution, but seems to work.

Krizai
  • 610
  • 10
  • 18