NSTextField - Selectable and mouseup event

391 views Asked by At

I have created my own NSTextField object:

@interface MyTitleLabel: NSTextField
@end

@implementation MyTitleLabel
- (void)mouseUp:(NSEvent *)event {
    NSLog(@"up");
}
@end

then initialised it like this:

MyTitleLabel* title_field = [[MyTitleLabel alloc] init];

The problem is if I have:

[title_field setSelectable:YES];

the mouseUp event is not triggered. But if I have it set to NO it is. However I need the NSTextField to be selectable and have a mouseUp event?

I also have an issue where - (void) rightMouseDown:(NSEvent *)event; is not called once I have selected some text in the NSTextField.

1

There are 1 answers

0
Jim Correia On

The functionality of text fields is implemented by NSTextFieldCell, which does most of the work, and the control which owns it, NSTextField.

In addition, while editing, the field editor comes into play.

Appleā€™s documentation explains this relationship:

https://developer.apple.com/library/content/documentation/TextFonts/Conceptual/CocoaTextArchitecture/TextFieldsAndViews/TextFieldsAndViews.html