3

In my ViewController I have set up a NSGestureRecognizer in order to know when particular TextField is clicked in by the user.

in viewDidLoad() override I have

let gesture = NSGestureRecognizer()
gesture.buttonMask = 0x1
gesture.numberOfClicksRequired = 1
gesture.target = self
gesture.action = #selector(ViewController.textOutputClicked)
textOutput.addGestureRecognizer(gesture)

then later in my ViewController I have

@objc func textOutputClicked(sender: NSGestureRecognizer){
    print("textOutput was clicked")
}

This all works and when I click in the textOutput field, I get the message "textOutput was clicked", however the processing of the click stops. What I want to do, and I'm not sure of the right way to describe it, is to continue passing the click onto the control to process. So for example the insert point is set in the control - right now this is ignored

Thanks GS

a.masri
  • 2,439
  • 1
  • 14
  • 32
Gazing South
  • 115
  • 8

1 Answers1

0

This works:

  @objc func textOutputClicked(sender: NSClickGestureRecognizer) {
// Invoke the default click behavior
NSApp.sendAction(#selector(NSResponder.mouseDown), to: nil, from: sender)}
T.J.
  • 3,942
  • 2
  • 32
  • 40