Re: selectText of NSTextField on focus

2015-07-09 Thread Richard Charles

 On Jul 8, 2015, at 8:52 AM, Richard Charles rcharles...@gmail.com wrote:
 
 Do you have any insight as to why the animation does not occur the first time 
 a text field is clicked?


Filed Apple bug report 21758024.

--Richard Charles


___

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

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

Re: selectText of NSTextField on focus

2015-07-08 Thread Willeke
 @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

You're almost there, do  [super mouseDown:event] first.

- Willeke
___

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

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

Re: selectText of NSTextField on focus

2015-07-08 Thread Richard Charles

 On Jul 8, 2015, at 7:00 AM, Willeke willeke2...@gmail.com wrote:
 
 @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
 
 You're almost there, do  [super mouseDown:event] first.

That works! Thank you so much for your help.

I have another question regarding focus ring animation for a text field. This 
is a document based application. In the document window there are many text 
fields. After opening a document window - the first time a text field is 
clicked there is no focus ring animation. Thereafter when any text field is 
clicked in the window the focus ring will animate.

Do you have any insight as to why the animation does not occur the first time a 
text field is clicked?

--Richard Charles


___

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

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

Re: selectText of NSTextField on focus

2015-07-07 Thread Richard Charles

 On Jul 7, 2015, at 8:27 AM, Willeke willeke2...@gmail.com wrote:
 
 Op 6 jul. 2015, om 18:15 heeft Richard Charles rcharles...@gmail.com 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 (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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: selectText of NSTextField on focus

2015-07-07 Thread Richard Charles

 On Jul 6, 2015, at 5:49 PM, Joel Norvell framewor...@yahoo.com wrote:
 
 Hi Richard,
 
 When the instance of your NSTextField subclass becomes first responder, you 
 have access to the NSText object (the field editor) and I believe you can use 
 its methods to select the text. (I don't see why you can't, but since I 
 haven't tried it myself, I'm saying I believe.)
 
 Sincerely,
 Joel
 
 Override - (BOOL)becomeFirstResponder in your subclass.
 
 Get the field editor:
 
 NSText * itsText = [[self window] fieldEditor:YES forObject:self];
 
 Use -selectAll or -setSelectedRange


Yes I have access to the field editor for the NSTextField. Directly setting the 
selection using the field editor however does not work.

- (BOOL)becomeFirstResponder
{
BOOL result = [super becomeFirstResponder];
if(result) {
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];
}
return result;
}

The above code does not work.

There is some sort of interaction between NSTextField (and or the field editor) 
and the runloop that has changed for the worse in OS X 10.10 Yosemite. The only 
code that works is to override becomeFirstResponder and then schedule the 
selectText: message with the runloop to execute after a non zero delay. I have 
not been able to get anything else to work.

A comment by Daniel Wabyick at the end of this stackoverflow question suggests 
that this was a problem in OS X 10.9 Mavericks but have been unable to 
duplicate that.

http://stackoverflow.com/questions/2195704/selecttext-of-nstextfield-on-focus

So in summary in OS X 10.10 selecting all the text of an NSTextField when the 
user clicks it has become difficult.

--Richard Charles


___

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

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

Re: selectText of NSTextField on focus

2015-07-07 Thread Willeke
 Op 6 jul. 2015, om 18:15 heeft Richard Charles rcharles...@gmail.com 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
___

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

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

Re: selectText of NSTextField on focus

2015-07-06 Thread Quincey Morris
On Jul 6, 2015, at 12:38 , Richard Charles rcharles...@gmail.com wrote:
 
 The delegate methods textDidBeginEditing: and controlTextDidBeginEditing: are 
 not called when clicking into the view. They are called when the first edit 
 is actually attempted. So that did not work.

My only other suggestion is that the frameworks might *always* issue a text 
selection, or at least the first time the text field is entered. (And you said 
this seems to be happening.) You might be able to override selectText: and use 
a flag to keep track of whether it’s the first time.



___

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

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

Re: selectText of NSTextField on focus

2015-07-06 Thread Mike Abdullah

 On 6 Jul 2015, at 20:38, Richard Charles rcharles...@gmail.com wrote:
 
 On Jul 6, 2015, at 12:12 PM, Gary L. Wade wrote:
 
 You want to select the text using the associated text view of the 
 NSTextField control.
 
 Not sure what you mean by the associated text view of the control. Do you 
 mean the field editor of the control? I have subclassed NSTextField and 
 overridden becomeFirstResponder. NSTextField is a subclass of NSControl which 
 is a subclass of NSView.
 
 
 On Jul 6, 2015, at 12:07 PM, Quincey Morris wrote:
 
 On Jul 6, 2015, at 10:54 , Richard Charles wrote:
 
  [self performSelector:@selector(selectText:) withObject:self 
 afterDelay:0];
 
 I dunno, but I suspect that this isn’t good enough. You’re merely guessing 
 that “on the next iteration of the run loop” is *after* the text field 
 finished becoming first responder, but it may take time to get the text 
 field into a state where its selection can be set.
 
 Yes I think that is the case. The following code works.
 
 [self performSelector:@selector(selectText:) withObject:self afterDelay:0.1];
 
 
 I’d suggest you try selecting the text in a delegate method 
 (textDidBeginEditing or controlTextDidBeginEditing) instead.
 
 The delegate methods textDidBeginEditing: and controlTextDidBeginEditing: are 
 not called when clicking into the view. They are called when the first edit 
 is actually attempted. So that did not work.
 
 
 In fiddling around with afterDelay: values this is what I found.
 
 afterDelay:0.01 // This did not work. Text not selected.
 
 afterDelay:0.02 // This works. Text is selected.
 
 afterDelay:0.1 // This works. Text is selected.
 
 afterDelay:1.0 // This works but the delay is too long.
 
 So do you think I am safe using this call.
 
 [self performSelector:@selector(selectText:) withObject:self afterDelay:0.1];

No.

Almost any time you have a delayed perform in your code, you’re doing something 
a bit dubious, and you’ve just wandered into proper dodgy territory, where your 
code is guaranteed to be unreliable.


___

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

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

Re: selectText of NSTextField on focus

2015-07-06 Thread Richard Charles

 On Jul 6, 2015, at 10:15 AM, Richard Charles rcharles...@gmail.com wrote:
 
 I have a NSTextField subclass that selects all of the text when the user 
 clicks it. This is accomplished by overriding becomeFirstResponder.
 
 - (BOOL)becomeFirstResponder
 {
BOOL result = [super becomeFirstResponder];
if(result) {
[self performSelector:@selector(selectText:) withObject:self 
 afterDelay:0];
}
return result;
 }
 
 http://stackoverflow.com/questions/2195704/selecttext-of-nstextfield-on-focus
 
 This has worked perfectly for years until 10.10 Yosemite. Now when the user 
 clicks into the text field nothing is selected.
 
 Also the following error will often occur on 10.10 Yosemite when clicking on 
 the text field.
 
 2015-07-06 10:09:04.287 MyApp[727:15035] Bad cursor rect event, flags = 256
 
 Does anyone have any insight into what is going on?
 
 Thanks so much.
 
 --Richard Charles

Update

The documentation for -[NSTextField selectText:] states If the receiver isn’t 
in some window’s view hierarchy, this method has no effect.”

I have verified that the text field is in the window’s view hierarchy. I have 
verified that -[NSTextField selectText:] is getting called. (Actually it is 
getting called twice, once by the frameworks for some reason, and once by me.) 
Calling the method -[NSTextField isSelectable] returns YES.

It appears that -[NSTextField selectText:] is broken in 10.10 Yosemite. It just 
does not work.

--Richard Charles


___

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

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

Re: selectText of NSTextField on focus

2015-07-06 Thread Quincey Morris
On Jul 6, 2015, at 10:54 , Richard Charles rcharles...@gmail.com wrote:

[self performSelector:@selector(selectText:) withObject:self 
 afterDelay:0];

I dunno, but I suspect that this isn’t good enough. You’re merely guessing that 
“on the next iteration of the run loop” is *after* the text field finished 
becoming first responder, but it may take time to get the text field into a 
state where its selection can be set.

I’d suggest you try selecting the text in a delegate method 
(textDidBeginEditing or controlTextDidBeginEditing) instead.


___

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

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

Re: selectText of NSTextField on focus

2015-07-06 Thread Richard Charles
 On Jul 6, 2015, at 12:12 PM, Gary L. Wade wrote:
 
 You want to select the text using the associated text view of the NSTextField 
 control.

Not sure what you mean by the associated text view of the control. Do you 
mean the field editor of the control? I have subclassed NSTextField and 
overridden becomeFirstResponder. NSTextField is a subclass of NSControl which 
is a subclass of NSView.


 On Jul 6, 2015, at 12:07 PM, Quincey Morris wrote:
 
 On Jul 6, 2015, at 10:54 , Richard Charles wrote:
 
   [self performSelector:@selector(selectText:) withObject:self 
 afterDelay:0];
 
 I dunno, but I suspect that this isn’t good enough. You’re merely guessing 
 that “on the next iteration of the run loop” is *after* the text field 
 finished becoming first responder, but it may take time to get the text field 
 into a state where its selection can be set.

Yes I think that is the case. The following code works.

[self performSelector:@selector(selectText:) withObject:self afterDelay:0.1];


 I’d suggest you try selecting the text in a delegate method 
 (textDidBeginEditing or controlTextDidBeginEditing) instead.

The delegate methods textDidBeginEditing: and controlTextDidBeginEditing: are 
not called when clicking into the view. They are called when the first edit is 
actually attempted. So that did not work.


In fiddling around with afterDelay: values this is what I found.

 afterDelay:0.01 // This did not work. Text not selected.

 afterDelay:0.02 // This works. Text is selected.

 afterDelay:0.1 // This works. Text is selected.

 afterDelay:1.0 // This works but the delay is too long.

So do you think I am safe using this call.

[self performSelector:@selector(selectText:) withObject:self afterDelay:0.1];

--Richard Charles


___

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

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

Re: selectText of NSTextField on focus

2015-07-06 Thread Gary L. Wade
You want to select the text using the associated text view of the NSTextField 
control.
--
Gary L. Wade (Sent from my iPhone)
http://www.garywade.com/

 On Jul 6, 2015, at 10:54 AM, Richard Charles rcharles...@gmail.com wrote:
 
 
 On Jul 6, 2015, at 10:15 AM, Richard Charles rcharles...@gmail.com wrote:
 
 I have a NSTextField subclass that selects all of the text when the user 
 clicks it. This is accomplished by overriding becomeFirstResponder.
 
 - (BOOL)becomeFirstResponder
 {
   BOOL result = [super becomeFirstResponder];
   if(result) {
   [self performSelector:@selector(selectText:) withObject:self 
 afterDelay:0];
   }
   return result;
 }
 
 http://stackoverflow.com/questions/2195704/selecttext-of-nstextfield-on-focus
 
 This has worked perfectly for years until 10.10 Yosemite. Now when the user 
 clicks into the text field nothing is selected.
 
 Also the following error will often occur on 10.10 Yosemite when clicking on 
 the text field.
 
 2015-07-06 10:09:04.287 MyApp[727:15035] Bad cursor rect event, flags = 256
 
 Does anyone have any insight into what is going on?
 
 Thanks so much.
 
 --Richard Charles
 
 Update
 
 The documentation for -[NSTextField selectText:] states If the receiver 
 isn’t in some window’s view hierarchy, this method has no effect.”
 
 I have verified that the text field is in the window’s view hierarchy. I have 
 verified that -[NSTextField selectText:] is getting called. (Actually it is 
 getting called twice, once by the frameworks for some reason, and once by 
 me.) Calling the method -[NSTextField isSelectable] returns YES.
 
 It appears that -[NSTextField selectText:] is broken in 10.10 Yosemite. It 
 just does not work.
 
 --Richard Charles

___

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

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

Re: selectText of NSTextField on focus

2015-07-06 Thread Quincey Morris
On Jul 6, 2015, at 16:16 , Richard Charles rcharles...@gmail.com wrote:
 
 Finder does something similar when renaming files and folders. The first 
 click selects the file or folder. The next click selects the name of the file 
 or folder ready for replacement. The third click will place the insertion 
 point somewhere within the text field ready for fine grain editing of the 
 file or folder name.

In general, if the text field doesn’t look editable until you “click to edit” 
(click #2 in the above, because I assume you don’t have click #1 at all in your 
app), then I think it’s fine for it to do a select all (or select 
something-predefined-like-Finder-does), because there’s no expectation from the 
appearance of the text that you might start with a drag-to-select-and-begin 
editing.

In your case, where the “click to edit” behavior is already expected by users, 
I don’t see a big problem in what you’re proposing, though I think the *classy* 
solution would be to have a subtle difference in appearance in the text field 
when a click is needed to start editing, even if it flies under the perceptual 
radar of experienced users.



___

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

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

Re: selectText of NSTextField on focus

2015-07-06 Thread Richard Charles

 On Jul 6, 2015, at 4:09 PM, Quincey Morris wrote:
 
 Incidentally — this is the part where we make you sorry you asked the 
 question — what are you trying to achieve here? Auto-self-selecting text 
 fields are an incredibly annoying UI, if the user is ever likely to want to 
 select only part of the field.

The text field contains a numeric values like 58.35 or -2.41 or something 
similar. The gold standard for this type of application and this type of data 
is to have the contents of the text field selected when the user clicks on it 
so he or she can quickly key in a new value to replace the existing value. 
Behavior other than this is a pain and not appreciated by typical users of this 
application.

Finder does something similar when renaming files and folders. The first click 
selects the file or folder. The next click selects the name of the file or 
folder ready for replacement. The third click will place the insertion point 
somewhere within the text field ready for fine grain editing of the file or 
folder name.

--Richard Charles


___

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

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

Re: selectText of NSTextField on focus

2015-07-06 Thread Joel Norvell
Hi Richard,

When the instance of your NSTextField subclass becomes first responder, you 
have access to the NSText object (the field editor) and I believe you can use 
its methods to select the text. (I don't see why you can't, but since I haven't 
tried it myself, I'm saying I believe.)
Sincerely,Joel
Override - (BOOL)becomeFirstResponder in your subclass.
Get the field editor:
NSText * itsText = [[self window] fieldEditor:YES forObject:self];
Use -selectAll or -setSelectedRange
___

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

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

Re: selectText of NSTextField on focus

2015-07-06 Thread Quincey Morris
On Jul 6, 2015, at 09:15 , Richard Charles rcharles...@gmail.com wrote:
 
 I have a NSTextField subclass that selects all of the text when the user 
 clicks it.

Incidentally — this is the part where we make you sorry you asked the question 
— what are you trying to achieve here? Auto-self-selecting text fields are an 
incredibly annoying UI, if the user is ever likely to want to select only part 
of the field.

If you’re selecting everything to allow it to be copied easily, then a “Copy” 
button next to the text is probably a better idea.

If you’re selecting everything in order to cause it to be deleted on the first 
keystroke, a “Clear” button (probably an “x” icon button) similar to iOS search 
fields is probably a better idea.

That is, if at all possible, augment the standard behavior, don’t change it.



___

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

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