> On Jul 7, 2015, at 8:27 AM, Willeke <[email protected]> wrote:
>
>> Op 6 jul. 2015, om 18:15 heeft Richard Charles <[email protected]> het
>> volgende geschreven:
>>
>> Does anyone have any insight into what is going on?
>>
> The animation of the focus ring isn't finished. If the focus ring is switched
> off, the text is selected.
>
> Safari's Address and Search field calls setSelectedRange: of currentEditor in
> mouseDown:
>
> - Willeke
Yes Safari’s Address and Search field has the behavior that I am looking for.
First click selects the entire text field and you also get an animated focus
ring.
Exactly how to achieve that on OS X 10.10 (with or without a focus ring) is
another matter. I have parred back my custom NSTextField subclass to just what
is shown below. A custom NSNumberFormatter is used but I removed it. The only
other thing going on is the text field is programmatically placed in the super
view.
====================
Your initial suggestion.
@implementation MyTextField
- (instancetype)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self.cell setFocusRingType:NSFocusRingTypeNone];
}
return self;
}
- (void)awakeFromNib
{
[self.cell setFocusRingType:NSFocusRingTypeNone];
}
- (BOOL)becomeFirstResponder
{
BOOL result = [super becomeFirstResponder];
if(result) {
[self performSelector:@selector(selectText:) withObject:self
afterDelay:0];
}
return result;
}
@end
RESULTS: Text is selected but rapidly changes to no selection. No focus ring as
expected. Intermittent error Bad cursor rect event, flags = 256.
====================
You say that Safari apparently does this.
@implementation MyTextField
- (void)mouseDown:(NSEvent *)event
{
NSText *editor = self.currentEditor;
assert(editor && "Current editor is nil!");
assert(editor.isFieldEditor && "Editor not a field editor!");
NSRange range = NSMakeRange(0, editor.string.length);
[editor setSelectedRange:range];
[super mouseDown:event];
}
@end
RESULTS: Text not selected. Focus ring normal. No error message.
====================
Another version of what Safari may do.
@implementation MyTextField
- (void)mouseDown:(NSEvent *)event
{
[self selectText:self];
[super mouseDown:event];
}
@end
RESULTS: Text is selected but rapidly changes to no selection. Focus ring is
intermittent. No error message.
====================
So in summary Safari’s Address and Search field has the behavior that I am
looking for. First click selects the entire text field and you also get an
animated focus ring. However on OS X 10.10 Yosemite nothing works for me except
performSelector:withObject:afterDelay: using a non-zero delay value.
--Richard Charles
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]