how to paste into the FindBar of an NSTextField?

I’m using the methods from macoslib to turn on the FindBar for a text field. It works great without much work at all, but you can’t paste into the find text field. Even if it has the focus and you have no handler for receiving paste menu events in the app it goes into the selection point main text field when it should go into the search text field.

I can tell if the search field is displayed or not, after all I turned it on, but I don’t know how to find out if the search text field itself has focus or if the focus is in the main parent text field. And even if I knew that how would I send the clipboard to the search field instead?

I have tried just invoking the insertText method on the NSTextField and that also just inserts the text into the main field even if the search field has the focus.

I am thinking that I need to look for a sub view? Or walk through the next responder or something like that to find the search bar and then the search text field within it and send it the insert message directly but I’m not entirely certain how to go about doing that.

I have access to the macoslib stuff as well as the Monkeybread plugin suite. I would normally just use those calls but that implementation only has .usesFindPanel and not the findBar. I was going to put in a feature request but I sorted it out with the stuff from osxlib :wink:

Any suggestions greatly appreciated :slight_smile: thank you!

maybe look into this old Post

I had used the Find Menu at that time (switch between Find Bar and Find Panel).
Try to see if it reacts the same as what you did.

That example does set the “usesFindBar” variable, but I can’t get it to run, it crashes after the open event no matter what I do to it so I can’t test to see if there is anything in there that lets you paste into the find bar…

ah, I did get it to run by removing most of the open event setup code but it does the same thing. Pasting into the search field of the search bar results in the pasted text getting put into the main field instead exactly as what is happening to me.

Which OSX version do you use?

I have tested this and get the same behavior on both El Capitan (10.11) and Sierra (10.12)

I’m on 10.10.5 , here it works, maybe it has some declares that don’t work > OSX 10.10

with FindBar
I can not paste into Searchfield with CMD+V , only with Contextmenu - Paste

with FindWindow
I can paste into Searchfield with CMD+V , can paste with Contextmenu - Paste

[quote=293436:@Axel Schneider]with FindBar
I can not paste into Searchield with CMD+V , only with Contexmenu - Paste


Ah, thats a good work around for the moment, I’ll tell people to use the contextual menu. But you can’t cmd-v either which is what I was trying to do so that doesn’t work even as far back as 10.10.

It makes a certain amount of sense. the menu handler is for the control, and the control now has multiple edit fields as child views, or sub views or whatever they are going to be called. the find bar is a set of controls embedded into the parent view. As far as Xojo is concerned it doesn’t know that there is more than one potential target for events in there. I can override the paste menu item, but I don’t know how to properly direct the text once I’ve got it. There must be a way to get the view that has the focus out of the control? Im probably using the terms wrong as I”m still a little shaky on the view/controller/etc stuff in OSX. I just need to get a reference to the view or control that has the focus so I can call the insert text method on the right thing.

In the TextEdit - FindBar I can paste into the searchfield with CMD+V

I’m pretty sure thats because Xojo overrides the paste event rather than just pass it down to the native control. I’m not sure how to undo that. If I could get a reference to the child control or the embedded view or however that works I’m sure I could pass the inserted text to it within the paste menu handler and take care of it myself. Thats what I don’t know how to do.