NSTextView cannot be selected inside text container insert

I set textContainerInset for NSTextView for some values.

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

How to make a selection of text in the input area? A text cursor appears, but nothing happens if I try to select a text area inside this insert.

Here is an additional code example that you can add to an empty 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]; } 
+7
objective-c cocoa nstextview
source share
1 answer

It seems that NSTextView believes in its inserts so much that it returns nil from hitTest for events on a nested area.

Which helped me override hitTest and return self for these cases, then TextView will handle such events correctly.

A bit of a risky decision, but it seems to work.

0
source share

All Articles